-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix mypy type checking via creating a nox typecheck session #13476
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
Draft
notatallshaw
wants to merge
21
commits into
pypa:main
Choose a base branch
from
notatallshaw:make-mypy-nox-session
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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.
Conversation
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
Invoke mypy with specific directories rather than a list of files found by pre-commit in the repository. This makes it catch more errors and issues.
Ah, there's a number of issues to work through, it seems I broke a few tests, and vendoring uses an old version of toml that can not correctly parse mixed type tables. I'll have to return to this next week. |
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.
This moves type checking out of the pre-commit and into a dedicated
nox -s typecheck
, this was inspired by and succeeds #12866.On top of the reasons outlined there there are two big issues with pip's type checking:
1. The additional dependencies in the
.pre-commit.yaml
are rarely updated and currently obsoleteThis PR fixes that by making the
nox -s typecheck
a new type-check dependency groups, which inherits from the existing test dependency group, a new docs dependency group, and a couple of other dependency groups that define various parts of pip.Taking the changes from #12866 and apply this increased the number of mypy errors from 0 to 48.
2. Vendored dependencies that use type stubs are not currently type checked
Pip vendors libraries like requests which do not include type hints, normally this is fixed by installing a stubs package,
types-requests
at type hint time, however this was not being picked up by mypy because it does not recognizedpip._vendor.requests
asrequests
.This can be fixed by doing all the imports of vendored libraries that don't include type hints like this (fortunately there are only a few libraries that need this):
Doing this increased the number of mypy errors from 48 to 71.
The rest of the PR is simply about fixing all the type check errors, I tried to be very conservative, using
# type: ignore
andcast
rather than making complicated refactors, but there are definitely a few bugs that were fixed in this as well.A side benefit is pre-commit runs much much faster, allowing you to enable it locally and it not be painful.