Skip to content

Commit

Permalink
Merge pull request #2503 from jakevdp/jsonschema-update
Browse files Browse the repository at this point in the history
Compatibility with jsonschema 4.0
  • Loading branch information
jakevdp authored Oct 17, 2021
2 parents 24c332c + 71dcaf0 commit 5bb1586
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class SchemaBase(object):
_schema = None
_rootschema = None
_class_is_valid_at_instantiation = True
_validator = jsonschema.Draft7Validator

def __init__(self, *args, **kwds):
# Two valid options for initialization, which should be handled by
Expand Down Expand Up @@ -439,7 +440,9 @@ def validate(cls, instance, schema=None):
if schema is None:
schema = cls._schema
resolver = jsonschema.RefResolver.from_schema(cls._rootschema or cls._schema)
return jsonschema.validate(instance, schema, resolver=resolver)
return jsonschema.validate(
instance, schema, cls=cls._validator, resolver=resolver
)

@classmethod
def resolve_references(cls, schema=None):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
entrypoints
jinja2
jsonschema<4.0
jsonschema>=3.0,<4.0
numpy
pandas>=0.18
toolz
5 changes: 4 additions & 1 deletion tools/schemapi/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class SchemaBase(object):
_schema = None
_rootschema = None
_class_is_valid_at_instantiation = True
_validator = jsonschema.Draft7Validator

def __init__(self, *args, **kwds):
# Two valid options for initialization, which should be handled by
Expand Down Expand Up @@ -437,7 +438,9 @@ def validate(cls, instance, schema=None):
if schema is None:
schema = cls._schema
resolver = jsonschema.RefResolver.from_schema(cls._rootschema or cls._schema)
return jsonschema.validate(instance, schema, resolver=resolver)
return jsonschema.validate(
instance, schema, cls=cls._validator, resolver=resolver
)

@classmethod
def resolve_references(cls, schema=None):
Expand Down

0 comments on commit 5bb1586

Please sign in to comment.