-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Fixes unique and equal checks #820
Conversation
Codecov Report
@@ Coverage Diff @@
## main #820 +/- ##
==========================================
+ Coverage 95.90% 96.11% +0.20%
==========================================
Files 17 18 +1
Lines 2587 2726 +139
Branches 299 310 +11
==========================================
+ Hits 2481 2620 +139
Misses 86 86
Partials 20 20
Continue to review full report at Codecov.
|
There's some interactions with And then the same for dict. |
Does this go in the right direction? Is there anything similar in the code you can point me to? |
Sorry for being terse -- yes that's in the right direction, but now the point is not to test the behavior in that test case itself (which is already covered elsewhere in the suite), it's whether #686 is fixed there. I.e. whether Let me know if that makes sense, if not will write something longer up. And thanks again. |
Thanks for the explanation. I added the examples you mentioned in the test 🙂 Maybe I miss something, but according to these tests this should be valid: https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/master/tests/draft2020-12/uniqueItems.json#L21 This is what actually fails
According to the spec this should be valid, right? |
Yes, sorry, I was typing too quickly -- valid, not invalid! I didn't try them with the change here but yeah we want to make sure the fix covers those as well. |
I removed the first check in |
jsonschema/_utils.py
Outdated
sliced = itertools.islice(sort, 1, None) | ||
|
||
for i, j in zip(sort, sliced): | ||
return not list_equal(list(i), list(j)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will now likely fail for triply-nested non-list containers.
It also will now do a lot of copying (every object will always be copied).
It's a bit better if we instead just use isinstance(collections.Sequence
or collections.Mapping
I suspect.
But yeah please check the additional nesting, I suspect we need even better tests that uncover that. Really the nice thing would be a hypothesis test that generates arbitrarily nested containers which it puts 0
s and False
s inside and ensures they're always considered unique. If you know how to do that that'd be great, otherwise yeah I suspect at least another manual test is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right, a tripple nesting caused new failures, this was related to the equal
function where the behavior was not extended. I refactored the tests and added some more cases as I'm not really sure how to create a data generator here and I'm afraid this makes debugging harder.
jsonschema/_utils.py
Outdated
e = unbool(e) | ||
|
||
for i in seen: | ||
if isinstance(i, dict) and isinstance(e, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line too I'm suspicious of if it still contains isinstance(, dict)
-- it'll fail for non-dict mappings then, so we need to exercise that case as well.
Let me know if that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been removed and it makes use of the equal
function instead.
Apologies for the delay here. I made some small tweaks, but have merged this. Much appreciated! I'll get you some feedback on the other PR next! |
Extends the equal check for dictionaries and lists.
This solves #686, but it's also usefull for newer spec implementations such as draft 2020-12