docs: document PEP 696 type parameter defaults#21729
Open
youdie006 wants to merge 1 commit into
Open
Conversation
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.
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 #17157.
Adds a "Type parameter defaults (PEP 696)" section to
docs/source/generics.rst, documentingdefault=forTypeVar/ParamSpec/TypeVarTuple(both the PEP 695 new-styleclass C[T = int]syntax and the legacytyping_extensionssyntax), 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.