Skip to content

Fix docs: clarify variance behavior for PEP 695 generics#20971

Open
dhanusharer wants to merge 1 commit intopython:masterfrom
dhanusharer:fix-doc-variance
Open

Fix docs: clarify variance behavior for PEP 695 generics#20971
dhanusharer wants to merge 1 commit intopython:masterfrom
dhanusharer:fix-doc-variance

Conversation

@dhanusharer
Copy link

@dhanusharer dhanusharer commented Mar 4, 2026

The documentation previously stated that user-defined generic classes
are invariant by default. This is true for the older TypeVar syntax,
but with the newer PEP 695 syntax (class MyCls[T]) type parameters
may be inferred as covariant when not used in invariant positions.

This PR updates the explanation in common_issues.rst to clarify this behavior.
Fixes #20366

@dhanusharer
Copy link
Author

I’ve opened a PR to clarify the variance behavior for PEP 695 generics in the documentation.
Please let me know if any wording changes are preferred.

@dhanusharer dhanusharer changed the title Fix docs: clarify variance behavior for PEP 695 generics Fix docs: clarify variance behavior for PEP 695 generics Fixes Mar 4, 2026
@dhanusharer dhanusharer changed the title Fix docs: clarify variance behavior for PEP 695 generics Fixes Fix docs: clarify variance behavior for PEP 695 generics Mar 4, 2026
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.

An empty generic class is covariant even though the doc says "all user-defined generic classes invariant by default"

1 participant