Skip to content

Commit

Permalink
Deprecate jsonschema.RefResolver.in_scope.
Browse files Browse the repository at this point in the history
It is unused in internal code and can be instead done via push/pop_scope
(at least until the entirety of RefResolver is deprecated).
  • Loading branch information
Julian committed Aug 25, 2021
1 parent dddac11 commit 5382037
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 20 additions & 2 deletions jsonschema/tests/test_deprecations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from unittest import TestCase

from jsonschema.validators import RefResolver


class TestDeprecations(TestCase):
def test_jsonschema_version(self):
def test_version(self):
"""
As of v4.0.0, __version__ is deprecated in favor of importlib.metadata.
"""
Expand All @@ -16,7 +18,7 @@ def test_jsonschema_version(self):
),
)

def test_jsonschema_validators_ErrorTree(self):
def test_validators_ErrorTree(self):
"""
As of v4.0.0, importing ErrorTree from jsonschema.validators is
deprecated in favor of doing so from jsonschema.exceptions.
Expand All @@ -30,3 +32,19 @@ def test_jsonschema_validators_ErrorTree(self):
"Importing ErrorTree from jsonschema.validators is deprecated",
),
)

def test_RefResolver_in_scope(self):
"""
As of v4.0.0, RefResolver.in_scope is deprecated.
"""

resolver = RefResolver.from_schema({})
with self.assertWarns(DeprecationWarning) as w:
with resolver.in_scope("foo"):
pass

self.assertTrue(
str(w.warning).startswith(
"jsonschema.RefResolver.in_scope is deprecated ",
),
)
5 changes: 5 additions & 0 deletions jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@ def in_scope(self, scope):
"""
Temporarily enter the given scope for the duration of the context.
"""
warnings.warn(
"jsonschema.RefResolver.in_scope is deprecated and will be "
"removed in a future release.",
DeprecationWarning,
)
self.push_scope(scope)
try:
yield
Expand Down

0 comments on commit 5382037

Please sign in to comment.