-
-
Couldn't load subscription status.
- Fork 1.9k
Update jsonschema.protocols.Validator.__init__
#14327
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.Validator.__init__
#14327
Conversation
The signature of this protocol has changed in recent versions of `jsonschema`. Update to match.
|
Diff from mypy_primer, showing the effect of this PR on open source code: check-jsonschema (https://github.com/python-jsonschema/check-jsonschema)
- src/check_jsonschema/schema_loader/main.py:190: error: Unexpected keyword argument "registry" for "Validator" [call-arg]
+ src/check_jsonschema/schema_loader/main.py:219: error: Missing positional argument "registry" in call to "Validator" [call-arg]
+ src/check_jsonschema/schema_loader/main.py:277: error: Missing positional argument "registry" in call to "Validator" [call-arg]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/specs/openapi/definitions.py: note: In function "make_validator":
+ src/schemathesis/specs/openapi/definitions.py:1918: error: Missing positional argument "registry" in call to "Validator" [call-arg]
+ src/schemathesis/specs/openapi/negative/__init__.py: note: In function "get_validator":
+ src/schemathesis/specs/openapi/negative/__init__.py:43: error: Missing positional argument "registry" in call to "Validator" [call-arg]
+ src/schemathesis/specs/openapi/negative/__init__.py: note: At top level:
|
|
☝️ Quick note on the above This is just what we get with a verbatim copy of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
In python-jsonschema/jsonschema#1396 , the type signature for `Validator.__init__` is updated to better match the runtime signature. This backports the fix to typeshed, keeping the copies of this data in sync. python-jsonschema/jsonschema#1396 is, itself, a response to feedback on `jsonschema` about the changes in `typeshed` python#14327. In addition to the `__init__` fix, a couple of additional small changes are made, both in `jsonschema` and here in the stubs: 1. In `jsonschema`, the type for `create()` in `validators.py` was updated to be notated with `-> type[Validator]`. This was necessary for internal testing on types to correctly read that validator classes created by this factory implement the protocol. 2. Here, in order to better guarantee that the types align, the `_Validator` class (which does not exist in `jsonschema`, but is only defined here in the stubs) now inherits from `Validator`. 3. The init signature for `_Validator` is updated to match 4. `tests/mypy_test.py` flags the `schema` instance variable annotation as mismatching between `Validator` and `_Validator`. Review against the `jsonschema` source reveals that `_Validator` was closer to correct, so `Validator` is fixed to match. Any further changes (e.g., elimination of `_Validator` or changing `create`'s return type annotation) are left as potential future work.
The signature of this protocol has changed in recent versions of
jsonschema. Update to match.Aside: There was a period (~1 year ago?) when I was actively working on
jsonschematypes with a plan to backport things from typeshed tojsonschema.I got a bit bogged down and the work is unfinished, but I would ultimately like to help make that happen. In the meantime, I still want to keep these in sync. :)