Repository navigation
Enable mypy type checking for pipenv's own code - #6745
Merged
Merged
Conversation
Add a mirrors-mypy pre-commit hook (which also gates CI via the lint job) and modernize the [tool.mypy] config: target Python 3.10, check pipenv/, exclude pipenv/vendor and pipenv/patched, and skip following imports into them. Fix the 201 existing errors, mostly by correcting annotations and converting legacy "# type:" comments to inline annotations. A few real issues surfaced along the way: - get_pip_args extended the arg list with a bare src_dir string (one arg per character); it now emits ["--src", src_dir]. No caller passes it today. - Lockfile.from_data built ProjectFile with a str location, which would break ProjectFile.write(); it now passes a Path. - Environment.is_satisfied and safe_import used pkg_resources APIs on importlib.metadata distributions in unreachable branches; switched to the importlib equivalents / removed the dead fallback. Vendored and patched packages are untouched. Closes #5335 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
|
|
||
| @overload | ||
| def add_ssh_scheme_to_git_uri(uri: str) -> str: ... |
| @overload | ||
| def add_ssh_scheme_to_git_uri(uri: str) -> str: ... | ||
| @overload | ||
| def add_ssh_scheme_to_git_uri(uri: bytes) -> bytes: ... |
| @overload | ||
| def add_ssh_scheme_to_git_uri(uri: bytes) -> bytes: ... | ||
| @overload | ||
| def add_ssh_scheme_to_git_uri(uri: None) -> None: ... |
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
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.
Closes #5335.
What
mirrors-mypy(v2.4.0) pre-commit hook. CI's lint job already runspre-commit run --all-files, so mypy now gates CI without a workflow change.[tool.mypy]config. It was targeting Python 3.7, pointing at atypeshed/dir that doesn't exist and generating an HTML report that needs lxml. It now targets 3.10, checkspipenv/, excludespipenv/vendor/andpipenv/patched/, and usesfollow_imports = "skip"so imports into them aren't followed.# type:comments to inline annotations. Ruff doesn't count type comments as using an import, so they caused unused-import errors once the typing names were imported.# type: ignoreis limited to code that's genuinely dynamic, such as the private_normalized_name/_pathattributes onimportlib.metadatadistributions and thelatest_versionattribute set on them at runtime.Small real fixes mypy surfaced
get_pip_argspassed a baresrc_dirstring tolist.extend, which would add one argument per character. It now produces["--src", src_dir]. No caller passes it today.Lockfile.from_databuilt aProjectFilewith astrlocation, which would breakProjectFile.write()(strhas no.open). It now passes aPath.Environment.is_satisfiedandsafe_importused pkg_resources APIs (.location,.has_metadata,.project_name,.activate) on stdlib distributions. Neither path can actually run, so this isn't a user-facing fix. Inis_satisfied, the earlierreq.specifiercheck always returns first. Thesafe_importfallback runs only when_modules[name]is falsy, which never happens. I switched the first to the importlib equivalents and removed the second.Follow-ups (not in this PR)
Mypy still skips the bodies of functions with no annotations. Turning on
check_untyped_defsto check them is the natural next step, best done one module at a time.Testing
mypy: no issues in 77 source filespre-commit run --all-files: all hooks passmainin this environment (local mirror/index fixtures), so this branch doesn't cause them.🤖 Generated with Claude Code