Skip to content

Commit 319cd84

Browse files
committed
And deprecate importing ErrorTree from jsonschema.validators.
1 parent 0975c62 commit 319cd84

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

jsonschema/tests/test_deprecations.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from unittest import TestCase
22

3-
import jsonschema
4-
53

64
class TestDeprecations(TestCase):
75
def test_jsonschema_version(self):
@@ -10,10 +8,25 @@ def test_jsonschema_version(self):
108
"""
119

1210
with self.assertWarns(DeprecationWarning) as w:
13-
jsonschema.__version__
11+
from jsonschema import __version__
1412

1513
self.assertTrue(
1614
str(w.warning).startswith(
1715
"Accessing jsonschema.__version__ is deprecated",
1816
),
1917
)
18+
19+
def test_jsonschema_validators_ErrorTree(self):
20+
"""
21+
As of v4.0.0, importing ErrorTree from jsonschema.validators is
22+
deprecated in favor of doing so from jsonschema.exceptions.
23+
"""
24+
25+
with self.assertWarns(DeprecationWarning) as w:
26+
from jsonschema.validators import ErrorTree
27+
28+
self.assertTrue(
29+
str(w.warning).startswith(
30+
"Importing ErrorTree from jsonschema.validators is deprecated",
31+
),
32+
)

jsonschema/validators.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from warnings import warn
99
import contextlib
1010
import json
11+
import warnings
1112

1213
from jsonschema import (
1314
_legacy_validators,
@@ -16,19 +17,24 @@
1617
_validators,
1718
exceptions,
1819
)
19-
# Sigh. https://gitlab.com/pycqa/flake8/issues/280
20-
# https://github.com/pyga/ebb-lint/issues/7
21-
# Imported for backwards compatibility.
22-
from jsonschema.exceptions import ErrorTree
23-
24-
ErrorTree
25-
2620

2721
validators = {}
2822
meta_schemas = _utils.URIDict()
2923
_VOCABULARIES = _utils.URIDict()
3024

3125

26+
def __getattr__(name):
27+
if name == "ErrorTree":
28+
warnings.warn(
29+
"Importing ErrorTree from jsonschema.validators is deprecated. "
30+
"Instead import it from jsonschema.exceptions.",
31+
DeprecationWarning,
32+
)
33+
from jsonschema.exceptions import ErrorTree
34+
return ErrorTree
35+
raise AttributeError(f"module {__name__} has no attribute {name}")
36+
37+
3238
def validates(version):
3339
"""
3440
Register the decorated validator for a ``version`` of the specification.

0 commit comments

Comments
 (0)