Add a command for running complete type checking with nox -s typecheck
(including vendored dependencies)
#13599
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 #13476 @notatallshaw did a lot of work to improve the typing situation in the codebase. Unfortunately that PR got quite big, and was ultimately closed.
During the development of that PR, I proposed an additional change which would trick
mypy
into learning about the full type information of the vendored dependencies (notatallshaw#4). That merge request meant that much of theif TYPE_CHECKING
tricks from #13476 would not be necessary, reducing the size of required change as well as reducing the duplication that the approach presented (and the risk of the two paths diverging).This PR is a targeted change to allow a
nox -s typecheck
command to run a completemypy
call with full dependency context. I have intentionally not tried to change anything in the codebase, including the existing (very limited)mypy
config nor actual type problems. I figure that knowing about the type issues is the first step to resolving them.There are a good number of follow-on activities from this PR, including making use of dependency groups, reusing the vendored dependency definitions from
vendor.txt
, fixing the typing issues, and adapting the CI systematically validate against this. I would propose not doing that in this PR to allow us to move forwards more easily (and ultimately, this PR doesn't change anything about the existing repository infra).The trick that I'm playing in this PR is to make a second
pip
package containing the_vendor
stubs which I show tomypy
along with the real./src/pip
viaMYPYPATH
. With the appropriate exclusions in the mypy config it then combines the two together to build the full context of the types used in./src/pip
.To demonstrate that this is doing what we expect/want, with this change I include the complete output with and without building
requests
stubs forpip._vendor.requests
. There is a lot of output, but the key observation is that withrequests
stubs, we are informed of potentially important information, for example:The line in question:
pip/src/pip/_internal/network/auth.py
Line 440 in ed05518
pip._vendor.requests
:Result when running against ./src/pip/_internal/network/session.py
Running:
nox -s typecheck -- ./src/pip/_internal/network/session.py
Result when running against ./src/pip/_internal/network/session.py **without type hint information about pip._vendor.requests**
Running:
nox -s typecheck -- ./src/pip/_internal/network/session.py