Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,26 @@ def uniq(container):
brute force when necessary.
"""
seen_keys = set()
supported = []
unsupported = []

for element in container:
key = _uniq_key(element)

if key is _UNSUPPORTED:
for previous in unsupported:
for previous in [*supported, *unsupported]:
if equal(previous, element):
return False
unsupported.append(element)
continue

if key in seen_keys:
return False
if any(equal(previous, element) for previous in unsupported):
return False

seen_keys.add(key)
supported.append(element)

return True

Expand Down
4 changes: 4 additions & 0 deletions jsonschema/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,7 @@ def test_unhashable_inside_mapping_falls_back(self):
self.assertTrue(
uniq([{"k": Unhashable(1)}, {"k": Unhashable(2)}]),
)

def test_equal_hashable_and_unhashable_values_are_not_unique(self):
self.assertFalse(uniq([{1}, frozenset({1})]))
self.assertFalse(uniq([frozenset({1}), {1}]))
Loading