summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-18 18:15:07 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-18 18:15:07 +0100
commit00031cb043763842266877923552e40f0c8f36b5 (patch)
treea7ff84ca2244b7832f857f4715b324576ef3a604
parenteb633b216bad1acb1a7739279c5ab83bdd63d7a1 (diff)
downloadjsonschema-00031cb043763842266877923552e40f0c8f36b5.tar.gz
Remove types_msg which implements really old draft-3 behavior.
Since then, types aren't objects, they're just strings. This just wastes time catching exceptions for newer drafts.
-rw-r--r--jsonschema/_legacy_validators.py9
-rw-r--r--jsonschema/_utils.py19
-rw-r--r--jsonschema/_validators.py4
3 files changed, 10 insertions, 22 deletions
diff --git a/jsonschema/_legacy_validators.py b/jsonschema/_legacy_validators.py
index 3a8b499..50fdbc8 100644
--- a/jsonschema/_legacy_validators.py
+++ b/jsonschema/_legacy_validators.py
@@ -193,8 +193,15 @@ def type_draft3(validator, types, instance, schema):
if validator.is_type(instance, type):
return
else:
+ reprs = []
+ for type in types:
+ try:
+ reprs.append(repr(type["name"]))
+ except Exception:
+ reprs.append(repr(type))
yield ValidationError(
- _utils.types_msg(instance, types), context=all_errors,
+ f"{instance!r} is not of type {', '.join(reprs)}",
+ context=all_errors,
)
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py
index 0af7355..54f9c22 100644
--- a/jsonschema/_utils.py
+++ b/jsonschema/_utils.py
@@ -120,25 +120,6 @@ def extras_msg(extras):
return ", ".join(repr(extra) for extra in extras), verb
-def types_msg(instance, types):
- """
- Create an error message for a failure to match the given types.
-
- If the ``instance`` is an object and contains a ``name`` property, it will
- be considered to be a description of that object and used as its type.
-
- Otherwise the message is simply the reprs of the given ``types``.
- """
-
- reprs = []
- for type in types:
- try:
- reprs.append(repr(type["name"]))
- except Exception:
- reprs.append(repr(type))
- return f"{instance!r} is not of type {', '.join(reprs)}"
-
-
def flatten(suitable_for_isinstance):
"""
isinstance() can accept a bunch of really annoying different types:
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py
index 100fa03..2c0df8f 100644
--- a/jsonschema/_validators.py
+++ b/jsonschema/_validators.py
@@ -9,7 +9,6 @@ from jsonschema._utils import (
find_additional_properties,
find_evaluated_item_indexes_by_schema,
find_evaluated_property_keys_by_schema,
- types_msg,
unbool,
uniq,
)
@@ -356,7 +355,8 @@ def type(validator, types, instance, schema):
types = ensure_list(types)
if not any(validator.is_type(instance, type) for type in types):
- yield ValidationError(types_msg(instance, types))
+ reprs = ", ".join(repr(type) for type in types)
+ yield ValidationError(f"{instance!r} is not of type {reprs}")
def properties(validator, properties, instance, schema):