Skip to content

Commit 5382037

Browse files
committed
Deprecate jsonschema.RefResolver.in_scope.
It is unused in internal code and can be instead done via push/pop_scope (at least until the entirety of RefResolver is deprecated).
1 parent dddac11 commit 5382037

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

jsonschema/tests/test_deprecations.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from unittest import TestCase
22

3+
from jsonschema.validators import RefResolver
4+
35

46
class TestDeprecations(TestCase):
5-
def test_jsonschema_version(self):
7+
def test_version(self):
68
"""
79
As of v4.0.0, __version__ is deprecated in favor of importlib.metadata.
810
"""
@@ -16,7 +18,7 @@ def test_jsonschema_version(self):
1618
),
1719
)
1820

19-
def test_jsonschema_validators_ErrorTree(self):
21+
def test_validators_ErrorTree(self):
2022
"""
2123
As of v4.0.0, importing ErrorTree from jsonschema.validators is
2224
deprecated in favor of doing so from jsonschema.exceptions.
@@ -30,3 +32,19 @@ def test_jsonschema_validators_ErrorTree(self):
3032
"Importing ErrorTree from jsonschema.validators is deprecated",
3133
),
3234
)
35+
36+
def test_RefResolver_in_scope(self):
37+
"""
38+
As of v4.0.0, RefResolver.in_scope is deprecated.
39+
"""
40+
41+
resolver = RefResolver.from_schema({})
42+
with self.assertWarns(DeprecationWarning) as w:
43+
with resolver.in_scope("foo"):
44+
pass
45+
46+
self.assertTrue(
47+
str(w.warning).startswith(
48+
"jsonschema.RefResolver.in_scope is deprecated ",
49+
),
50+
)

jsonschema/validators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,11 @@ def in_scope(self, scope):
691691
"""
692692
Temporarily enter the given scope for the duration of the context.
693693
"""
694+
warnings.warn(
695+
"jsonschema.RefResolver.in_scope is deprecated and will be "
696+
"removed in a future release.",
697+
DeprecationWarning,
698+
)
694699
self.push_scope(scope)
695700
try:
696701
yield

0 commit comments

Comments
 (0)