Skip to content

Add comprehensive type annotations and PEP 561 py.typed marker #3075

@rahuldevikar

Description

@rahuldevikar

What's the problem this feature will solve?

virtualenv currently has very limited type annotation coverage (~26%). The sibling project tox already ships with ~92% coverage and a py.typed marker. This means:

  • Downstream consumers and plugins don't get type checking benefits when importing from virtualenv
  • IDE autocompletion and inline documentation are degraded for the public API (cli_run, session_via_cli, etc.)
  • Contributors have no type-level guardrails catching bugs at development time
  • The existing ty type checker environments in tox.toml can't enforce correctness without annotations to check

Describe the solution you'd like

  • Add return-type and parameter-type annotations to all functions and methods across the source tree
  • Add a PEP 561 py.typed marker file so type checkers recognize virtualenv as an inline-typed package
  • Enable ruff's ANN lint rules (currently blanket-ignored with the comment "no type checking added yet"), keeping only ANN003 and ANN401 as targeted exceptions
  • Harden the ty check tox environments with --error-on-warning to prevent regressions

Alternative Solutions

  • Maintain a separate virtualenv-stubs package — higher maintenance burden, easily falls out of sync
  • Use stub files (.pyi) alongside source — duplicates every signature, same sync problem
  • Inline annotations (proposed) match how tox already handles this and are the lowest-maintenance path

Additional context

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions