From 19dccbf28a93276ac1afe8cc4b8bd28cf72dd392 Mon Sep 17 00:00:00 2001 From: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com> Date: Sun, 12 Jul 2026 12:52:16 -0700 Subject: [PATCH] Fix uniq comparisons across hashability paths Compare fallback values against values handled by the structural hash. Add regression coverage for both input orderings. --- jsonschema/_utils.py | 6 +++++- jsonschema/tests/test_utils.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 3177caea3..a15e1cb4a 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -217,13 +217,14 @@ 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) @@ -231,8 +232,11 @@ def uniq(container): 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 diff --git a/jsonschema/tests/test_utils.py b/jsonschema/tests/test_utils.py index f716a36a1..ac6c2974f 100644 --- a/jsonschema/tests/test_utils.py +++ b/jsonschema/tests/test_utils.py @@ -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}]))