summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2019-01-23 16:52:54 -0500
committerJulian Berman <Julian@GrayVines.com>2019-01-23 16:52:54 -0500
commit207bb1ca96611916a8bea07a7bed2d94c0722e03 (patch)
tree313e4809ce589b7a4276d7c0afb71e9a6234fe58
parent59124e7710ee27c9f4904698dbb631211f92aa5c (diff)
downloadjsonschema-207bb1ca96611916a8bea07a7bed2d94c0722e03.tar.gz
Make sure DEFAULT_TYPES is still present on instances.
This is even more awful, so ughhhhhhhhhhhhhhhhhhhhhh but obviously, in 2019, we still don't have a decent, comprehensive deprecation library that does all these things properly.
-rw-r--r--jsonschema/tests/test_validators.py23
-rw-r--r--jsonschema/validators.py25
2 files changed, 36 insertions, 12 deletions
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index fb9dc3c..9624c96 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -56,7 +56,8 @@ class TestCreateAndExtend(SynchronousTestCase):
expected_types = {u"array", u"boolean", u"integer", u"null", u"number",
u"object", u"string"}
self.assertEqual(set(self.Validator.DEFAULT_TYPES), expected_types)
- self.assertEqual(len(self.flushWarnings()), 1)
+ self.assertEqual(set(self.Validator({}).DEFAULT_TYPES), expected_types)
+ self.assertEqual(len(self.flushWarnings()), 2)
def test_init(self):
schema = {u"startswith": u"foo"}
@@ -136,6 +137,7 @@ class TestCreateAndExtend(SynchronousTestCase):
self.Validator.VALIDATORS,
Extended.DEFAULT_TYPES,
+ Extended({}).DEFAULT_TYPES,
self.flushWarnings()[0]["message"],
), (
dict(original, new=new),
@@ -144,6 +146,7 @@ class TestCreateAndExtend(SynchronousTestCase):
original,
self.Validator.DEFAULT_TYPES,
+ self.Validator.DEFAULT_TYPES,
self.flushWarnings()[0]["message"],
),
)
@@ -265,6 +268,24 @@ class TestLegacyTypeCheckingDeprecation(SynchronousTestCase):
"DEFAULT_TYPES",
)
+ def test_accessing_default_types_on_the_instance_warns(self):
+ Validator = validators.create(meta_schema={}, validators={})
+ self.assertFalse(self.flushWarnings())
+
+ self.assertWarns(
+ DeprecationWarning,
+ (
+ "The DEFAULT_TYPES attribute is deprecated. "
+ "See the type checker attached to this validator instead."
+ ),
+ # https://tm.tl/9363 :'(
+ sys.modules[self.assertWarns.__module__].__file__,
+
+ getattr,
+ Validator({}),
+ "DEFAULT_TYPES",
+ )
+
def test_providing_types_to_init_warns(self):
Validator = validators.create(meta_schema={}, validators={})
self.assertFalse(self.flushWarnings())
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index b70a1d5..557996a 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -109,18 +109,20 @@ def _generate_legacy_type_checks(types=()):
return definitions
+def _DEFAULT_TYPES(self):
+ warn(
+ (
+ "The DEFAULT_TYPES attribute is deprecated. "
+ "See the type checker attached to this validator instead."
+ ),
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self._DEFAULT_TYPES
+
+
class _DefaultTypesDeprecatingMetaClass(type):
- @property
- def DEFAULT_TYPES(self):
- warn(
- (
- "The DEFAULT_TYPES attribute is deprecated. "
- "See the type checker attached to this validator instead."
- ),
- DeprecationWarning,
- stacklevel=2,
- )
- return self._DEFAULT_TYPES
+ DEFAULT_TYPES = property(_DEFAULT_TYPES)
def _id_of(schema):
@@ -222,6 +224,7 @@ def create(
TYPE_CHECKER = type_checker
ID_OF = staticmethod(id_of)
+ DEFAULT_TYPES = property(_DEFAULT_TYPES)
_DEFAULT_TYPES = dict(default_types)
def __init__(