Skip to content

docs: document PEP 696 type parameter defaults#21729

Open
youdie006 wants to merge 1 commit into
python:masterfrom
youdie006:docs/pep-696-typevar-defaults
Open

docs: document PEP 696 type parameter defaults#21729
youdie006 wants to merge 1 commit into
python:masterfrom
youdie006:docs/pep-696-typevar-defaults

Conversation

@youdie006

Copy link
Copy Markdown

Closes #17157.

Adds a "Type parameter defaults (PEP 696)" section to docs/source/generics.rst, documenting default= for TypeVar / ParamSpec / TypeVarTuple (both the PEP 695 new-style class C[T = int] syntax and the legacy typing_extensions syntax), which mypy supports but did not document.

Covers: basic usage with class and function examples, the ordering rule (a defaulted type parameter can't be followed by a non-defaulted one), defaults having to satisfy bounds/constraints, defaults referencing an earlier type parameter, and the version note (new syntax needs 3.13; legacy via typing_extensions).

Every documented behavior is grounded in an existing mypy test (check-python313.test / check-typevar-defaults.test) — nothing is documented that mypy doesn't implement.

Test plan

sphinx-build -b html -n source _build (nitpicky) -> build succeeded with 0 warnings; the new section renders with the :pep: role resolved to PEP 696.


AI disclosure: this PR was drafted with Claude Code (AI-assisted). Every documented behavior is cross-referenced to a mypy test, and the sphinx nitpicky build is clean.

Add a Type parameter defaults section to generics.rst covering default= for
TypeVar/ParamSpec/TypeVarTuple in both new-style and legacy syntax, grounded
in the existing PEP 696 test cases.
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.

Document TypeVarLike defaults

1 participant