File tree Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Original file line number Diff line number Diff line change 1
1
from unittest import TestCase
2
2
3
- import jsonschema
4
-
5
3
6
4
class TestDeprecations (TestCase ):
7
5
def test_jsonschema_version (self ):
@@ -10,10 +8,25 @@ def test_jsonschema_version(self):
10
8
"""
11
9
12
10
with self .assertWarns (DeprecationWarning ) as w :
13
- jsonschema . __version__
11
+ from jsonschema import __version__
14
12
15
13
self .assertTrue (
16
14
str (w .warning ).startswith (
17
15
"Accessing jsonschema.__version__ is deprecated" ,
18
16
),
19
17
)
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
+ )
Original file line number Diff line number Diff line change 8
8
from warnings import warn
9
9
import contextlib
10
10
import json
11
+ import warnings
11
12
12
13
from jsonschema import (
13
14
_legacy_validators ,
16
17
_validators ,
17
18
exceptions ,
18
19
)
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
-
26
20
27
21
validators = {}
28
22
meta_schemas = _utils .URIDict ()
29
23
_VOCABULARIES = _utils .URIDict ()
30
24
31
25
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
+
32
38
def validates (version ):
33
39
"""
34
40
Register the decorated validator for a ``version`` of the specification.
You can’t perform that action at this time.
0 commit comments