add comprehensive type annotations across the entire codebase#3076
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
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. |
| 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. |
There was a problem hiding this comment.
I don't think we should supress any globally, these should be suprerssed on a case by case basis.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Generally we should understand why it's unresolved instead of supress, applies for all supresses.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This has been addressed now. Thanks for the feedback!!!
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:
py.typedso downstream consumers get inline type information.pyproject.tomlwith 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.typeandtype-3.8tox environments intox.toml.Fixes: #3075
Thanks for contributing, make sure you address all the checklists (for details on how see development documentation)
tox -e fix)docs/changelogfolder