-
-
Notifications
You must be signed in to change notification settings - Fork 607
Closed
Closed
Bug
Copy link
Description
The signature of jsonschema.protocols.Validator is backward incompatible with earlier versions and definitions such as jsonschema.Draft202012Validator in static type checking. Specifically, an registry argument is now needed, as far as static checking is concerned, in instantiating an object of a class that is casted as a jsonschema.protocols.Validator.
# as_validator.py
from typing import cast, Type
from jsonschema import Draft202012Validator
from jsonschema.protocols import Validator
validator_cls = cast(Type[Validator], Draft202012Validator)
schema = {"maxItems" : 2}
validator_cls(schema).validate([2, 3, 4])Running mypy on tmp.py produces the following error.
(dandi-schema) ➜ dandi-schema git:(devendorize) ✗ mypy as_validator.py
as_validator.py:12: error: Missing positional argument "registry" in call to "Validator" [call-arg]
validator_cls(schema).validate([2, 3, 4])
^~~~~~~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 1 source file)# as_draft_202012_validator.py
from jsonschema import Draft202012Validator
schema = {"maxItems" : 2}
Draft202012Validator(schema).validate([2, 3, 4])On the other hand, running mypy on as_draft_202012_validator.py doesn't produce any error.
(dandi-schema) ➜ dandi-schema git:(devendorize) ✗ mypy as_draft_202012_validator.py
Success: no issues found in 1 source fileThis incompatibility exists, at least, in three places source code, documentation, and the types-jsonschema package.
- Source code which mentioned earlier
- Documentation at 4.18.0 and beyond
types-jsonschemaat the current version of4.24.0.20250708
Context:
Python used: 3.9.16
Metadata
Metadata
Assignees
Labels
No labels