Update jsonschema stubs to track latest changes#14591
Merged
srittau merged 2 commits intoAug 20, 2025
Merged
Conversation
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.
This comment has been minimized.
This comment has been minimized.
Collaborator
|
Considering this is tracking changes made in jsonschema 4.25.1 (if I understand correctly), we should update the |
Contributor
Author
|
I'm not sure, since this is actually more accurate to the runtime behavior in earlier versions as well? 4.25.1 updates the I suppose on the grounds that "it tracks upstream and also fixes bugs in the types", it should update? I'll push the change, but LMK if it makes sense to back it out. |
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: 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/generation/coverage.py: note: In function "cover_schema_iter":
- src/schemathesis/generation/coverage.py:622: error: Missing positional argument "registry" in call to "Validator" [call-arg]
- src/schemathesis/generation/coverage.py:632: error: Missing positional argument "registry" in call to "Validator" [call-arg]
- src/schemathesis/generation/coverage.py: note: In function "_negative_type":
- src/schemathesis/generation/coverage.py:1250: 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:
- src/schemathesis/specs/openapi/stateful/__init__.py: note: In function "into_step_input":
- src/schemathesis/specs/openapi/stateful/__init__.py:291: error: Missing positional argument "registry" in call to "Validator" [call-arg]
check-jsonschema (https://github.com/python-jsonschema/check-jsonschema)
+ src/check_jsonschema/formats/__init__.py:56: error: Unused "type: ignore" comment [unused-ignore]
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
+ discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
|
srittau
approved these changes
Aug 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onjsonschemaabout the changes intypeshed#14327.In addition to the
__init__fix, a couple of additional small changes are made, both injsonschemaand here in the stubs:In
jsonschema, the type forcreate()invalidators.pywas 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.Here, in order to better guarantee that the types align, the
_Validatorclass (which does not exist injsonschema, but is only defined here in the stubs) now inherits fromValidator.The init signature for
_Validatoris updated to matchtests/mypy_test.pyflags theschemainstance variable annotation as mismatching betweenValidatorand_Validator. Review against thejsonschemasource reveals that_Validatorwas closer to correct, soValidatoris fixed to match.Any further changes (e.g., elimination of
_Validatoror changingcreate's return type annotation) are left as potential future work.