You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following code PyCharm finds 1 warning and 1 error:
importjsonschemav: jsonschema.protocols.Validator=jsonschema.Draft202012Validator({})
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# Expected type 'Validator', got 'Draft202012Validator' insteadprint(isinstance(jsonschema.Draft202012Validator({}), jsonschema.protocols.Validator))
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# Only @runtime_checkable protocols can be used with instance and class checks
mypy finds them too:
test004.py:3: error: Incompatible types in assignment (expression has type "Draft202012Validator", variable has type "Validator") [assignment]
test004.py:3: note: Following member(s) of "Draft202012Validator" have conflicts:
test004.py:3: note: Expected:
test004.py:3: note: def evolve(self, **kwargs: Any) -> Validator
test004.py:3: note: Got:
test004.py:3: note: def evolve(self, **changes: Any) -> _Validator
test004.py:3: note: schema: expected "dict[Any, Any] | bool", got "bool | Mapping[str, Any]"
test004.py:6: error: Only @runtime_checkable protocols can be used with instance and class checks [misc]
Found 2 errors in 1 file (checked 1 source file)
But the code works and prints "True".
Why doesn't Validator protocol work as expected? Is this jsonschema library issue? Or am I doing something wrong here (and if yes, how to do it correctly)?
checked with 4.25.1 and still I can't resolve the new signature in VSCode or PyCharm. Any hint how to update the caches etc. for it is greatly appreciated.
very odd theses editors just don't pickup the new functionality.
You need to wait for the change to percolate out, which has hardly even started yet. I'll probably work on backporting to typeshed during my train ride home today. The timeline is:
I backport to typeshed
typeshed maintainers accept the tweak
typeshed releases new packages
editors and type checkers pick up on the new typeshed packages
if you are installing types-jsonschema yourself, update that too
then you see the fix
So please don't expect same-day resolution. Getting the change applied here is only one part of the coordinated ecosystem of packages which are implicated in your editor showing you a type hint.
Activity
vkuehn commentedon Aug 18, 2025
I have kind of the same issue. It looks like upgrading the library does cause the issue.
After Upgrading Draft7Validator Signature still looks like in the old version where there was no registry
Draft7Validator
class Draft7Validator(
schema: _Schema,
resolver: Any | None = ...,
format_checker: Any | None = ...
)
For a fresh installed version the signature looks like
class Draft7Validator(
schema: Schema,
resolver: Any | None = None,
format_checker: FormatChecker | None = None,
*,
registry: SchemaRegistry = ...,
_resolver: Any | None = None
)
let me know if I should open a separate issue
vkuehn commentedon Aug 18, 2025
@sirosen thanks for the upgrade !
checked with 4.25.1 and still I can't resolve the new signature in VSCode or PyCharm. Any hint how to update the caches etc. for it is greatly appreciated.
very odd theses editors just don't pickup the new functionality.
sirosen commentedon Aug 18, 2025
You need to wait for the change to percolate out, which has hardly even started yet. I'll probably work on backporting to typeshed during my train ride home today. The timeline is:
types-jsonschemayourself, update that tooSo please don't expect same-day resolution. Getting the change applied here is only one part of the coordinated ecosystem of packages which are implicated in your editor showing you a type hint.
vkuehn commentedon Aug 19, 2025
thanks.
@t1m013y sorry kind of hijacking your issue