Skip to content

Commit 00031cb

Browse files
committed
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.
1 parent eb633b2 commit 00031cb

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

jsonschema/_legacy_validators.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,15 @@ def type_draft3(validator, types, instance, schema):
193193
if validator.is_type(instance, type):
194194
return
195195
else:
196+
reprs = []
197+
for type in types:
198+
try:
199+
reprs.append(repr(type["name"]))
200+
except Exception:
201+
reprs.append(repr(type))
196202
yield ValidationError(
197-
_utils.types_msg(instance, types), context=all_errors,
203+
f"{instance!r} is not of type {', '.join(reprs)}",
204+
context=all_errors,
198205
)
199206

200207

jsonschema/_utils.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,6 @@ def extras_msg(extras):
120120
return ", ".join(repr(extra) for extra in extras), verb
121121

122122

123-
def types_msg(instance, types):
124-
"""
125-
Create an error message for a failure to match the given types.
126-
127-
If the ``instance`` is an object and contains a ``name`` property, it will
128-
be considered to be a description of that object and used as its type.
129-
130-
Otherwise the message is simply the reprs of the given ``types``.
131-
"""
132-
133-
reprs = []
134-
for type in types:
135-
try:
136-
reprs.append(repr(type["name"]))
137-
except Exception:
138-
reprs.append(repr(type))
139-
return f"{instance!r} is not of type {', '.join(reprs)}"
140-
141-
142123
def flatten(suitable_for_isinstance):
143124
"""
144125
isinstance() can accept a bunch of really annoying different types:

jsonschema/_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
find_additional_properties,
1010
find_evaluated_item_indexes_by_schema,
1111
find_evaluated_property_keys_by_schema,
12-
types_msg,
1312
unbool,
1413
uniq,
1514
)
@@ -356,7 +355,8 @@ def type(validator, types, instance, schema):
356355
types = ensure_list(types)
357356

358357
if not any(validator.is_type(instance, type) for type in types):
359-
yield ValidationError(types_msg(instance, types))
358+
reprs = ", ".join(repr(type) for type in types)
359+
yield ValidationError(f"{instance!r} is not of type {reprs}")
360360

361361

362362
def properties(validator, properties, instance, schema):

0 commit comments

Comments
 (0)