-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add type checking #277
Open
JonathonReinhart
wants to merge
18
commits into
main
Choose a base branch
from
add-type-checking
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add type checking #277
Conversation
This file contains 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
JonathonReinhart
force-pushed
the
add-type-checking
branch
5 times, most recently
from
January 14, 2024 18:33
fdbd2d8
to
3a4679d
Compare
This adds an initial [tool.mypy] section to pyproject.toml which checks modules which have no typing errors. We set python_version = "3.7" to ensure we are always checking against the syntax and stdlib of our lowest supported Python version. This also adds mypy to requirements.txt for development.
This also updates the single() implementation, replacing the use of _SENTINEL as a nothing-to-return marker with a separate bool variable. Note that we need to use both collections.abc.Iterable (for isinstance()) and typing.Iterable (for type annotation) until Python 3.9 (#265). If we attempt to use the former for type annotation in Python < 3.9, we get the following error: TypeError: 'ABCMeta' object is not subscriptable This also simplifies coerce_sequence() to always return a list, removing the return-type argument.
This updates git_describe() to return Optional[GitDescribe] to simplify typing. The whole file looks much closer now to this (and in some ways better): https://github.com/JonathonReinhart/scuba/blob/18135bb19a/scuba/version.py This also adds importlib-metadata to requirements.txt for development. This is because even though we're running with Python 3.11 on Debian 12, we specify python_version = "3.8" in pyproject.toml, which means the backport is needed for type checking.
For some reason, running mypy v1.8.0 --python-version=3.8 in a Python 3.11 venv doesn't pick up the importlib_resources types, even when the (runtime-unnecessary) importlib-resources package is installed, so we have to add a cast.
Also take the opportunity to clean up some wildcard imports.
One slightly annoying issue is that I like to set attributes to None in close() after they've been closed. But this requires marking their types as Optional, which requires checking that they are not None where they are used. A well-polished API would check and raise a "closed" exception. For now, we just assert. This also fixes #278.
JonathonReinhart
force-pushed
the
add-type-checking
branch
from
January 16, 2024 03:16
3a4679d
to
97ca99d
Compare
We also add types-pyinstaller to requirements.txt.
JonathonReinhart
force-pushed
the
add-type-checking
branch
from
January 16, 2024 03:25
97ca99d
to
35d08c5
Compare
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.
No description provided.