Skip to content

Commit

Permalink
Improve the hashability of referencing exceptions when they contain h…
Browse files Browse the repository at this point in the history
…ashable data.

Closes: #1126
  • Loading branch information
Julian committed Jul 18, 2023
1 parent 3fb1617 commit 801a4ce
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
@@ -1,3 +1,8 @@
v4.18.4
=======

* Improve the hashability of wrapped referencing exceptions when they contain hashable data.

v4.18.3
=======

Expand Down
3 changes: 3 additions & 0 deletions jsonschema/exceptions.py
Expand Up @@ -230,6 +230,9 @@ def __eq__(self, other):
def __getattr__(self, attr):
return getattr(self._wrapped, attr)

def __hash__(self):
return hash(self._wrapped)

def __repr__(self):
return f"<WrappedReferencingError {self._wrapped!r}>"

Expand Down
18 changes: 18 additions & 0 deletions jsonschema/tests/test_deprecations.py
Expand Up @@ -211,6 +211,24 @@ def test_catching_Unresolvable_via_RefResolutionError(self):
(u.exception, "Unresolvable: urn:nothing")
)

def test_WrappedReferencingError_hashability(self):
"""
Ensure the wrapped referencing errors are hashable when possible.
"""
with self.assertWarns(DeprecationWarning):
from jsonschema import RefResolutionError

validator = validators.Draft202012Validator({"$ref": "urn:nothing"})

with self.assertRaises(referencing.exceptions.Unresolvable) as u:
validator.validate(12)

with self.assertRaises(RefResolutionError) as e:
validator.validate(12)

self.assertIn(e.exception, {u.exception})
self.assertIn(u.exception, {e.exception})

def test_Validator_subclassing(self):
"""
As of v4.12.0, subclassing a validator class produces an explicit
Expand Down

0 comments on commit 801a4ce

Please sign in to comment.