-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update jsonschema.protocols #12484
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
Update jsonschema.protocols #12484
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Remove `resolver` param from __init__()
Diff from mypy_primer, showing the effect of this PR on open source code: schemathesis (https://github.com./schemathesis/schemathesis)
+ src/schemathesis/specs/openapi/schemas.py: note: In member "validator_cls" of class "BaseOpenAPISchema":
+ src/schemathesis/specs/openapi/schemas.py:647: error: Incompatible return value type (got "Type[Draft202012Validator]", expected "Type[Validator]") [return-value]
+ src/schemathesis/specs/openapi/schemas.py:648: error: Incompatible return value type (got "Type[Draft4Validator]", expected "Type[Validator]") [return-value]
|
I've started looking into this but truly, typing jsonschema seems more and more like a can of worms that I don't have the time to dig into. I'm afraid to go forward with this PR if it risks creating more problems for others users. For now, I'll just live with my mypy ignore comment and hope for progress in python-jsonschema/jsonschema#1027 |
I'm very inexperienced with type annotations so I hope my conclusions were correct. Recently, when working on a project using jsonschema I had trouble with the following error raised by mypy:
However, ever since jsonschema 4.18 (commit), the Validator protocol's
__init__()
method has a aregistry
parameter.From what I gather, the
protocols.pyi
stubs were never updated to reflect this change.I basically only copied the signatures from the current version to
protocols.pyi
. Here's hoping that's what I'm supposed to do.Edit: I left in theresolver
param which was removed from the library's signature in the same release, to be replaced byregistry
. However, according to the docs,resolver
is only deprecated and it is still entirely possible to use it. Removing it from the stub would lead to the same error for all current users of theresolver
param. This goes somewhat counter to CONTRIBUTING.md but I felt this scenario is a little different than what is described there. This looks like an "error" in the function signature, not the docs.