-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
__replace__
was added onto NamedTuple
as a part of 3.13 related changes, however, instead of returning None
, it should return Self
. Looking in cpython we can see this is the case.
Furthermore, this is important for compatibility with copy.replace
. In python/typeshed#12262 we're adding a protocol that requires replaceable objects implement:
class _SupportsReplace(Protocol):
def __replace__(self, *args: Any, **kwargs: Any) -> Self: ...
With namedtuple.__replace__
returning None
, users will return into false positives here, when in reality it should work just fine.