Skip to content

Allowed function-like type validators #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from jsonschema.exceptions import ErrorTree # Backwards compat # noqa: F401
from jsonschema.exceptions import RefResolutionError, SchemaError, UnknownType

type_backup = type

_unset = _utils.Unset()

Expand Down Expand Up @@ -142,7 +143,10 @@ def is_type(self, instance, type):
)
if is_number and bool not in pytypes:
return False
return isinstance(instance, pytypes)
if isinstance(pytypes, (type_backup, tuple)):
return isinstance(instance, pytypes)
elif callable(pytypes):
return pytypes(instance)

def is_valid(self, instance, _schema=None):
error = next(self.iter_errors(instance, _schema), None)
Expand Down