Skip to content

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

Closed
wants to merge 7 commits into from
Closed

Conversation

mmarseu
Copy link

@mmarseu mmarseu commented Aug 5, 2024

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:

 error: Unexpected keyword argument "registry" for "Validator"  [call-arg]

However, ever since jsonschema 4.18 (commit), the Validator protocol's __init__() method has a a registry 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 the resolver param which was removed from the library's signature in the same release, to be replaced by registry. 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 the resolver 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.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
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/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]

@mmarseu
Copy link
Author

mmarseu commented Oct 14, 2024

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

@mmarseu mmarseu closed this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants