diff options
author | Julian Berman <Julian@GrayVines.com> | 2021-08-21 16:14:35 +0100 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2021-08-21 16:14:35 +0100 |
commit | 319cd84470939bb274a70e25ce12e2240b22720d (patch) | |
tree | 7c193df723b72a7211998d49c49176d89646f812 | |
parent | 0975c62c71ce747acee620282e84c87cf353dca8 (diff) | |
download | jsonschema-319cd84470939bb274a70e25ce12e2240b22720d.tar.gz |
And deprecate importing ErrorTree from jsonschema.validators.
-rw-r--r-- | jsonschema/tests/test_deprecations.py | 19 | ||||
-rw-r--r-- | jsonschema/validators.py | 20 |
2 files changed, 29 insertions, 10 deletions
diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py index ff1e316..7d51a41 100644 --- a/jsonschema/tests/test_deprecations.py +++ b/jsonschema/tests/test_deprecations.py @@ -1,7 +1,5 @@ from unittest import TestCase -import jsonschema - class TestDeprecations(TestCase): def test_jsonschema_version(self): @@ -10,10 +8,25 @@ class TestDeprecations(TestCase): """ with self.assertWarns(DeprecationWarning) as w: - jsonschema.__version__ + from jsonschema import __version__ self.assertTrue( str(w.warning).startswith( "Accessing jsonschema.__version__ is deprecated", ), ) + + def test_jsonschema_validators_ErrorTree(self): + """ + As of v4.0.0, importing ErrorTree from jsonschema.validators is + deprecated in favor of doing so from jsonschema.exceptions. + """ + + with self.assertWarns(DeprecationWarning) as w: + from jsonschema.validators import ErrorTree + + self.assertTrue( + str(w.warning).startswith( + "Importing ErrorTree from jsonschema.validators is deprecated", + ), + ) diff --git a/jsonschema/validators.py b/jsonschema/validators.py index e0e2f8d..0314559 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -8,6 +8,7 @@ from urllib.request import urlopen from warnings import warn import contextlib import json +import warnings from jsonschema import ( _legacy_validators, @@ -16,19 +17,24 @@ from jsonschema import ( _validators, exceptions, ) -# Sigh. https://gitlab.com/pycqa/flake8/issues/280 -# https://github.com/pyga/ebb-lint/issues/7 -# Imported for backwards compatibility. -from jsonschema.exceptions import ErrorTree - -ErrorTree - validators = {} meta_schemas = _utils.URIDict() _VOCABULARIES = _utils.URIDict() +def __getattr__(name): + if name == "ErrorTree": + warnings.warn( + "Importing ErrorTree from jsonschema.validators is deprecated. " + "Instead import it from jsonschema.exceptions.", + DeprecationWarning, + ) + from jsonschema.exceptions import ErrorTree + return ErrorTree + raise AttributeError(f"module {__name__} has no attribute {name}") + + def validates(version): """ Register the decorated validator for a ``version`` of the specification. |