Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach unbool about deeply nested objects/arrays #697

Conversation

ryangalamb
Copy link

Fixes #686

I'm aware that TypeChecker throws a wrench into this, but I want to see if this approach seems reasonable to you before I go any farther.

@codecov
Copy link

codecov bot commented Jun 13, 2020

Codecov Report

Merging #697 into master will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #697      +/-   ##
==========================================
- Coverage   95.25%   95.22%   -0.03%     
==========================================
  Files          18       18              
  Lines        2716     2703      -13     
  Branches      321      318       -3     
==========================================
- Hits         2587     2574      -13     
  Misses        106      106              
  Partials       23       23              
Impacted Files Coverage Δ
jsonschema/tests/test_jsonschema_test_suite.py 100.00% <ø> (ø)
jsonschema/_utils.py 93.90% <100.00%> (-0.84%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ffc81e...c6f3cf7. Read the comment docs.

Now that `unbool` creates a hashable, the fallback options for `uniq`
are unnecessary.
@ryangalamb ryangalamb force-pushed the rjmill/fix-equality-bools-1s-and-0s branch from 1f6d09f to c6f3cf7 Compare June 13, 2020 23:31
@willson-chen
Copy link
Contributor

This PR looks good to me. I have tested the following four scenarios, and all got the expected result.

Code

from jsonschema.validators import Draft7Validator, exceptions
validator = Draft7Validator({'type': 'array', 'uniqueItems': True})

# scene 1: nested dictionary
print(exceptions.best_match(validator.iter_errors([{'1': {'1': '1'}}, {'1': {'1': '1'}}])))
print("-----------------------------------------------------------------------")

# scene 2: nested list
print(exceptions.best_match(validator.iter_errors([[[False], [0]], [False, 0], [[False], [0]]])))
print("-----------------------------------------------------------------------")

# scene 3: nested tuple
print(exceptions.best_match(validator.iter_errors([('1', (1, 0), '1'), ('1', (1, 0), '1')])))
print("-----------------------------------------------------------------------")

# scene 4: nested set
print(exceptions.best_match(validator.iter_errors([{1, 2, 3}, {1, 2, 3}, {1, 1, 1}])))

Result

[{'1': {'1': '1'}}, {'1': {'1': '1'}}] has non-unique elements

Failed validating 'uniqueItems' in schema:
    {'type': 'array', 'uniqueItems': True}

On instance:
    [{'1': {'1': '1'}}, {'1': {'1': '1'}}]
-----------------------------------------------------------------------
[[[False], [0]], [False, 0], [[False], [0]]] has non-unique elements

Failed validating 'uniqueItems' in schema:
    {'type': 'array', 'uniqueItems': True}

On instance:
    [[[False], [0]], [False, 0], [[False], [0]]]
-----------------------------------------------------------------------
[('1', (1, 0), '1'), ('1', (1, 0), '1')] has non-unique elements

Failed validating 'uniqueItems' in schema:
    {'type': 'array', 'uniqueItems': True}

On instance:
    [('1', (1, 0), '1'), ('1', (1, 0), '1')]
-----------------------------------------------------------------------
[{1, 2, 3}, {1, 2, 3}, {1}] has non-unique elements

Failed validating 'uniqueItems' in schema:
    {'type': 'array', 'uniqueItems': True}

On instance:
    [{1, 2, 3}, {1, 2, 3}, {1}]

@Julian Julian closed this Oct 20, 2020
@Julian Julian deleted the branch python-jsonschema:master October 20, 2020 16:37
Julian added a commit that referenced this pull request Oct 30, 2023
95fe6ca Merge pull request #694 from json-schema-org/heterogeneous-additionalItems
9c88a0b Merge pull request #697 from json-schema-org/gregsdennis/add-ref-into-known-nonapplicator
fea2cf1 add tests for 2019 and 2020
6695ca3 add optional tests for `$ref`ing into known non-applicator keywords
cda4281 Merge pull request #695 from json-schema-org/ether/clean-up-subSchemas
7b9f45c move subSchemas-defs.json to subSchemas.json
e41ec0e remove unused definition files
349c5a8 Merge pull request #692 from json-schema-org/ether/fix-subSchemas-refs
451baca Merge pull request #670 from marksparkza/invalid-output-test
b8da838 Add tests for heterogeneous arrays with additionalItems
6d7a44b fix subschema locations and their $refs
ea0b63c Remove invalid output tests

git-subtree-dir: json
git-subtree-split: 95fe6ca20a90a019f4538f3670b6dd49d91dfdee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[[False], [0]] should be considered unique
3 participants