-
-
Notifications
You must be signed in to change notification settings - Fork 719
Thoroughly test type annotations, and resolve errors #1112
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
base: master
Are you sure you want to change the base?
Conversation
Type checking across all supported Pythons revealed errors: * Python 3.9 doesn't have `typing.TypeAlias`. This is fixed by importing `typing_extensions.TypeAlias`. * Python 3.9 doesn't support type alias `x | y` union syntax. This is fixed by using `Union[x, y]` syntax. * Setting `warn-return-any = true` revealed that when `cryptography` isn't installed, `RSAPrivateKey.sign()` has an unknown signature. The return type cannot be `cast()` because it's redundant if `cryptography` is installed. This is fixed by adding `signature: bytes = key.sign()` and then returning `signature`. * All disabled error codes have been removed. * The pre-commit hook for mypy has been removed. It's less robust than running the test suite. * All functions and methods are now fully type-annotated.
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.
Pull Request Overview
This PR improves type checking infrastructure by removing the mypy pre-commit hook, adding tox-based mypy testing across all supported Python versions (3.9-3.14), and increasing mypy strictness. The changes enable type annotations to be tested in both crypto and nocrypto configurations across all Python versions.
- Added tox environments for running mypy on Python 3.9-3.14 with optional crypto extras
- Increased mypy strictness by enabling
strict = trueandwarn_return_any = true - Replaced Python 3.10+ union syntax with
Union[]for Python 3.9 compatibility
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tox.ini | Added mypy test environments for all Python versions (3.9-3.14) and a labeled group for running them |
| pyproject.toml | Enabled strict mypy checking and simplified configuration |
| jwt/jwks_client.py | Updated type ignore comment to be more specific |
| jwt/api_jwt.py | Added Python 3.9 support for TypeAlias, replaced union syntax, added cast for type safety |
| jwt/algorithms.py | Added Python 3.9 support for TypeAlias, replaced union syntax, added type annotations and return type hints |
| CHANGELOG.rst | Documented the development changes |
| .pre-commit-config.yaml | Removed mypy pre-commit hook |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
please cross check the suggestions
|
Just did. Copilot was wrong on all counts, and no changes are needed. |
Type checking across all supported Pythons revealed errors:
Python 3.9 doesn't have
typing.TypeAlias.This is fixed by importing
typing_extensions.TypeAlias.Python 3.9 doesn't support type alias
x | yunion syntax.This is fixed by using
Union[x, y]syntax.Setting
warn-return-any = truerevealed that whencryptographyisn't installed,RSAPrivateKey.sign()has an unknown signature. The return type cannot becast()because it's redundant ifcryptographyis installed.This is fixed by adding
signature: bytes = key.sign()and then returningsignature.All disabled error codes have been removed.
The pre-commit hook for mypy has been removed. It's less robust than running the test suite.
All functions and methods are now fully type-annotated.