Skip to content

Commit

Permalink
Remove types_msg which implements really old draft-3 behavior.
Browse files Browse the repository at this point in the history
Since then, types aren't objects, they're just strings.

This just wastes time catching exceptions for newer drafts.
  • Loading branch information
Julian committed Aug 18, 2021
1 parent eb633b2 commit 00031cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
9 changes: 8 additions & 1 deletion jsonschema/_legacy_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
19 changes: 0 additions & 19 deletions jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions jsonschema/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
find_additional_properties,
find_evaluated_item_indexes_by_schema,
find_evaluated_property_keys_by_schema,
types_msg,
unbool,
uniq,
)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 00031cb

Please sign in to comment.