summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2018-09-03 10:54:34 +0100
committerJulian Berman <Julian@GrayVines.com>2018-09-03 10:54:34 +0100
commit3eabefb0c538d44bec414d84a7ab576dac5de6ee (patch)
tree179bcd031b3f3916bfecd368b966f60b90b288ba
parent6a7d58f58d1587460084aa7e46c764d6430be707 (diff)
downloadjsonschema-3eabefb0c538d44bec414d84a7ab576dac5de6ee.tar.gz
Make draft3's any type not be special cased.
Previously, is_any was uncovered/dead code. As a crazy 'side effect', you can redefine the any type now. Go wild.
-rw-r--r--jsonschema/_validators.py2
-rw-r--r--jsonschema/tests/test_jsonschema_test_suite.py5
-rw-r--r--jsonschema/tests/test_validators.py15
3 files changed, 20 insertions, 2 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py
index b1045d6..ef4cd83 100644
--- a/jsonschema/_validators.py
+++ b/jsonschema/_validators.py
@@ -322,8 +322,6 @@ def type_draft3(validator, types, instance, schema):
all_errors = []
for index, type in enumerate(types):
- if type == "any":
- return
if validator.is_type(type, "object"):
errors = list(validator.descend(instance, type, schema_path=index))
if not errors:
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py
index 57b420f..82276e2 100644
--- a/jsonschema/tests/test_jsonschema_test_suite.py
+++ b/jsonschema/tests/test_jsonschema_test_suite.py
@@ -142,6 +142,11 @@ TestDraft6 = DRAFT6.to_unittest_testcase(
TestDraft3LegacyTypeCheck = DRAFT3.to_unittest_testcase(
DRAFT3.tests_of(name="type"),
name="TestDraft3LegacyTypeCheck",
+ skip=skip_tests_containing_descriptions(
+ type={
+ "any": "Interestingly this couldn't really be done w/the old API.",
+ },
+ ),
Validator=create(
meta_schema=Draft3Validator.META_SCHEMA,
validators=Draft3Validator.VALIDATORS,
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index 26f7e38..9ebff12 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -1034,6 +1034,21 @@ class TestDraft3Validator(AntiDraft6LeakMixin, ValidatorTestMixin, TestCase):
validator = self.Validator({"type": "any"})
validator.validate(object())
+ def test_any_type_is_redefinable(self):
+ """
+ Sigh, because why not.
+ """
+ Crazy = validators.extend(
+ self.Validator,
+ type_checker=self.Validator.TYPE_CHECKER.redefine(
+ "any", lambda checker, thing: isinstance(thing, int),
+ )
+ )
+ validator = Crazy({"type": "any"})
+ validator.validate(12)
+ with self.assertRaises(ValidationError):
+ validator.validate("foo")
+
def test_is_type_is_true_for_any_type(self):
self.assertTrue(self.validator.is_valid(object(), {"type": "any"}))