diff --git a/schema/__init__.py b/schema/__init__.py index 31bd71b..3ffea33 100644 --- a/schema/__init__.py +++ b/schema/__init__.py @@ -459,7 +459,11 @@ def validate(self, data: Any, **kwargs: Dict[str, Any]) -> Any: for skey in sorted_skeys: svalue = s[skey] try: - nkey = Schema(skey, error=e).validate(key, **kwargs) + if isinstance(skey, (tuple, frozenset)): + Schema(hash(skey), error=e).validate(hash(key), **kwargs) + nkey = skey + else: + nkey = Schema(skey, error=e).validate(key, **kwargs) except SchemaError: pass else: diff --git a/test_schema.py b/test_schema.py index 2d7a495..6f3c836 100644 --- a/test_schema.py +++ b/test_schema.py @@ -1985,3 +1985,25 @@ def test_callable_error(): except SchemaError as ex: e = ex assert e.errors == ["This is the error message"] + + +def test_tuple_key_of_dict(): + # this is a simplified regression test of the bug in github issue #312 + assert Schema({('map_point', 'to', 'map_polygon'): {}}).validate( + {('map_point', 'to', 'map_polygon'): {}} + ) == {('map_point', 'to', 'map_polygon'): {}} + with SE: + assert Schema({('map_point', 'to', 'map_polygon'): {}}).validate( + {('map_polygon', 'to', 'map_polygon'): {}} + ) == {('map_polygon', 'to', 'map_polygon'): {}} + + +def test_frozenset_key_of_dict(): + # this is a simplified regression test of the bug in github issue #312 + assert Schema({frozenset(('map_point', 'to', 'map_polygon')): {}}).validate( + {frozenset(('map_point', 'to', 'map_polygon')): {}} + ) == {frozenset(('map_point', 'to', 'map_polygon')): {}} + with SE: + assert Schema({frozenset(('map_point', 'to', 'map_polygon')): {}}).validate( + {frozenset(('map_polygon', 'to', 'map_polygon')): {}} + ) == {frozenset(('map_polygon', 'to', 'map_polygon')): {}} \ No newline at end of file