Skip to content

add comprehensive type annotations across the entire codebase#3076

Merged
gaborbernat merged 17 commits into
pypa:mainfrom
rahuldevikar:feature/type-annotations
Feb 26, 2026
Merged

add comprehensive type annotations across the entire codebase#3076
gaborbernat merged 17 commits into
pypa:mainfrom
rahuldevikar:feature/type-annotations

Conversation

@rahuldevikar

@rahuldevikar rahuldevikar commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

This change adds full return-type and parameter-type annotations to all ~625 functions and methods across the entire virtualenv source tree. It brings the codebase from ~26% type coverage to near-complete coverage, matching the standard already established in the sibling tox project.

Key changes include:

  • PEP 561 marker: Added py.typed so downstream consumers get inline type information.
  • Ruff ANN rules enabled: Replaced the blanket "ANN" ignore in pyproject.toml with only the two specific exceptions (ANN003, ANN401), and added FBT001 to the global ignore since the existing boolean-positional-argument function signatures are public API.
  • ty type checker hardened: Added --error-on-warning to both type and type-3.8 tox environments in tox.toml.
  • All modules annotated: config, run, create (including CPython/PyPy/GraalPy/RustPython builders), activation (all 7 shells), seed (pip install, wheels, periodic update), app_data, util (lock, path, subprocess, zipapp), and discovery — every function now has explicit parameter types and return types.
  • Both linters pass clean: ruff check and ty check --python-version 3.14 --error-on-warning report zero errors. All pre-existing tests continue to pass.

Fixes: #3075

Thanks for contributing, make sure you address all the checklists (for details on how see development documentation)

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

@rahuldevikar rahuldevikar marked this pull request as ready for review February 26, 2026 06:21
@rahuldevikar

Copy link
Copy Markdown
Contributor Author

The Windows CI failure (gw0 node down: Not properly terminated) is not related to this PR — it's a known, long-standing flakiness in pytest-xdist on Windows.

Comment thread docs/development.rst Outdated
setting).
- Place imports that are only needed for type checking inside an ``if TYPE_CHECKING:`` block to avoid runtime overhead.
- Ruff's ``ANN`` rules are enabled. Only ``ANN003`` (``**kwargs``) and ``ANN401`` (``typing.Any``) are suppressed
globally because they are too noisy for the plugin API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should supress any globally, these should be suprerssed on a case by case basis.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ANN003 can be removed from the ignore list entirely — all . **kwargs are now annotated
Fpr ANN401, I'll remove it from the global ignore and per-lin #noqa to the call sites that need Any. These are all cases where the type is truely dynamic by design

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed now. Thanks for the feedback!!!

"__VIRTUAL_ENV__": str(creator.dest),
"__VIRTUAL_NAME__": creator.env_name,
"__BIN_NAME__": str(creator.bin_dir.relative_to(creator.dest)),
"__VIRTUAL_NAME__": creator.env_name, # ty: ignore[unresolved-attribute]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we should understand why it's unresolved instead of supress, applies for all supresses.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the activators type the creator parameter as Creator, but env_name and bin_dir are actually defined on Describe. These two classes are only combined in the cocrete subclass for eg: VirtualenvBuiltin. So, from the type checker's perspective Creator does not have env_name or bin_dir

I can add env_name and bin_dir as abstract properties on Creator itself. Same goes for other ty:ignore comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed now. Thanks for the feedback!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add comprehensive type annotations and PEP 561 py.typed marker

2 participants