Skip to content

Commit

Permalink
Remove optimization that no longer yields a major improvement in Pyth…
Browse files Browse the repository at this point in the history
…on 3.11 or PyPy
  • Loading branch information
jpmckinney committed Jul 11, 2023
1 parent a97f769 commit 7375c54
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions libcove/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,6 @@
REQUIRED_RE = re.compile(r"^'([^']+)'")


# This function was inlined in jsonschema 4.
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 "%r is not of type %s" % (instance, ", ".join(reprs))


def type_validator(validator, types, instance, schema):
"""
Replace the jsonschema type validator to use for-loop instead of slower
any() with generator expression.
https://github.com/OpenDataServices/lib-cove/pull/66
"""
types = ensure_list(types)

for type in types:
if validator.is_type(instance, type):
break
else:
yield ValidationError(types_msg(instance, types))


class TypeChecker:
def is_type(self, instance, type):
if type == "string":
Expand Down Expand Up @@ -97,9 +60,6 @@ def is_type(self, instance, type):
# Otherwise we could cause conflicts with other software in the same process.
validator = jsonschema.validators.extend(
jsonschema.validators.Draft4Validator,
validators={
"type": type_validator,
},
type_checker=TypeChecker(),
)

Expand Down

0 comments on commit 7375c54

Please sign in to comment.