You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
copy.replace type inference regression: breaks Self-returning __replace__ with bound TypeVar #21672
typeshed PR python/typeshed#14786 (synced into mypy) changed copy.replace from a bound-TypeVar signature to a covariant protocol. This breaks copy.replace for __replace__ methods that return Self (dataclasses, namedtuples, etc.) when the argument is a bounded TypeVar.
The bound-TypeVar approach preserved the argument type; the covariant protocol loses it because _RT_co is inferred from the protocol method return type which, for Self, resolves at the upper bound level.
Note
The motivation for python/typeshed#14786 was mypy issue #19694 which is about dataclasses.replace (not copy.replace), so the PR did not actually address its intended target.
changed the title [-]copy.replace type inference regression: breaks Self-returning __replace__ with bound TypeVar[/-][+]`copy.replace` type inference regression: breaks Self-returning __replace__ with bound TypeVar[/+]on Jul 3, 2026
Activity
[-]copy.replace type inference regression: breaks Self-returning __replace__ with bound TypeVar[/-][+]`copy.replace` type inference regression: breaks Self-returning __replace__ with bound TypeVar[/+]trim21 commentedon Aug 9, 2026
relative: python/typeshed#15973 python/typeshed#15997