diff options
Diffstat (limited to 'jsonschema')
-rw-r--r-- | jsonschema/protocols.py | 6 | ||||
-rw-r--r-- | jsonschema/tests/test_deprecations.py | 16 | ||||
-rw-r--r-- | jsonschema/tests/test_validators.py | 7 | ||||
-rw-r--r-- | jsonschema/validators.py | 16 |
4 files changed, 39 insertions, 6 deletions
diff --git a/jsonschema/protocols.py b/jsonschema/protocols.py index c9c71dc..eb67444 100644 --- a/jsonschema/protocols.py +++ b/jsonschema/protocols.py @@ -65,6 +65,11 @@ class Validator(Protocol): a resolver that will be used to resolve :kw:`$ref` properties (JSON references). If unprovided, one will be created. + .. deprecated:: v4.18.0 + + `RefResolver` has been deprecated in favor of `referencing`, + and with it, this argument. + format_checker: if provided, a checker which will be used to assert about @@ -108,7 +113,6 @@ class Validator(Protocol): def __init__( self, schema: Mapping | bool, - resolver: jsonschema.validators._RefResolver | None = None, format_checker: jsonschema.FormatChecker | None = None, ) -> None: ... diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py index 898a792..d21065f 100644 --- a/jsonschema/tests/test_deprecations.py +++ b/jsonschema/tests/test_deprecations.py @@ -125,6 +125,22 @@ class TestDeprecations(TestCase): ), ) + def test_Validator_resolver(self): + """ + As of v4.18.0, accessing Validator.resolver is deprecated. + """ + + validator = validators.Draft7Validator({}) + with self.assertWarns(DeprecationWarning) as w: + self.assertIsInstance(validator.resolver, validators._RefResolver) + + self.assertEqual(w.filename, __file__) + self.assertTrue( + str(w.warning).startswith( + "Accessing Draft7Validator.resolver is ", + ), + ) + def test_Validator_subclassing(self): """ As of v4.12.0, subclassing a validator class produces an explicit diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index f94b69b..a76b247 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -1735,10 +1735,9 @@ class ValidatorTestMixin(MetaSchemaTestsMixin, object): validator.validate(instance) def test_it_creates_a_ref_resolver_if_not_provided(self): - self.assertIsInstance( - self.Validator({}).resolver, - validators._RefResolver, - ) + with self.assertWarns(DeprecationWarning): + resolver = self.Validator({}).resolver + self.assertIsInstance(resolver, validators._RefResolver) def test_it_upconverts_from_deprecated_RefResolvers(self): ref, schema = "someCoolRef", {"type": "integer"} diff --git a/jsonschema/validators.py b/jsonschema/validators.py index be5ff18..8abec84 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -212,6 +212,18 @@ def create( @property def resolver(self): + warnings.warn( + ( + f"Accessing {self.__class__.__name__}.resolver is " + "deprecated as of v4.18.0, in favor of the " + "https://github.com/python-jsonschema/referencing " + "library, which provides more compliant referencing " + "behavior as well as more flexible APIs for " + "customization." + ), + DeprecationWarning, + stacklevel=2, + ) if self._resolver is None: self._resolver = _RefResolver.from_schema( self.schema, @@ -265,7 +277,9 @@ def create( return # Temporarily needed to eagerly create a resolver... - self.resolver + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + self.resolver scope = id_of(_schema) if scope: self.resolver.push_scope(scope) |