diff --git a/mypy/semanal_namedtuple.py b/mypy/semanal_namedtuple.py index bf526a1ee990..768dd265b338 100644 --- a/mypy/semanal_namedtuple.py +++ b/mypy/semanal_namedtuple.py @@ -57,7 +57,6 @@ TYPED_NAMEDTUPLE_NAMES, AnyType, CallableType, - Instance, LiteralType, TupleType, Type, @@ -632,10 +631,9 @@ def add_method( args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED_OPT) for var in vars], ) if self.options.python_version >= (3, 13): - type_vars = [tv for tv in info.defn.type_vars] add_method( "__replace__", - ret=Instance(info, type_vars), + ret=None, args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED_OPT) for var in vars], ) diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index f10217b9aa5f..e9d156754d9c 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -1407,23 +1407,9 @@ from typing import NamedTuple class A(NamedTuple): x: int -replaced = A(x=0).__replace__(x=1) -reveal_type(replaced) # N: Revealed type is "__main__.A" - +A(x=0).__replace__(x=1) A(x=0).__replace__(x="asdf") # E: Argument "x" to "__replace__" of "A" has incompatible type "str"; expected "int" A(x=0).__replace__(y=1) # E: Unexpected keyword argument "y" for "__replace__" of "A" - -from typing import TypeVar, Generic - -T = TypeVar("T") - -class GenericA(NamedTuple, Generic[T]): - x: T - -replaced_2 = GenericA(x=0).__replace__(x=1) -reveal_type(replaced_2) # N: Revealed type is "__main__.GenericA" -GenericA(x=0).__replace__(x="abc") # E: Argument "x" to "__replace__" of "GenericA" has incompatible type "str"; expected "int" - [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi]