diff options
author | Julian Berman <Julian@GrayVines.com> | 2021-08-25 11:02:25 +0100 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2021-08-25 11:02:25 +0100 |
commit | 53820379c4e9b44ae69790947a0793267a04d47d (patch) | |
tree | 179dc667122adc0a668fbabce80ad55a03cba9d9 | |
parent | dddac11d8b96dbbf95dfddcff6a0507ff302a48d (diff) | |
download | jsonschema-53820379c4e9b44ae69790947a0793267a04d47d.tar.gz |
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).
-rw-r--r-- | jsonschema/tests/test_deprecations.py | 22 | ||||
-rw-r--r-- | jsonschema/validators.py | 5 |
2 files changed, 25 insertions, 2 deletions
diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py index 18d8622..0ddc375 100644 --- a/jsonschema/tests/test_deprecations.py +++ b/jsonschema/tests/test_deprecations.py @@ -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. """ @@ -16,7 +18,7 @@ class TestDeprecations(TestCase): ), ) - 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. @@ -30,3 +32,19 @@ class TestDeprecations(TestCase): "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 ", + ), + ) diff --git a/jsonschema/validators.py b/jsonschema/validators.py index e085ebb..f94e9d0 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -691,6 +691,11 @@ class RefResolver(object): """ 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 |