Skip to content

Commit 45ee5a3

Browse files
authored
fix: prevent crash on dataclass with PEP695 TypeVarTuple on py3.13 (#19565)
Fixes #19559. Replaces ad-hoc Instance creation with regular `fill_typevars`. Huge thanks to @A5rocks for the pointer!
1 parent 7c4ec52 commit 45ee5a3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

mypy/plugins/dataclasses.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,12 @@ def _add_dunder_replace(self, attributes: list[DataclassAttribute]) -> None:
410410
for attr in attributes
411411
if attr.is_in_init
412412
]
413-
type_vars = [tv for tv in self._cls.type_vars]
414413
add_method_to_class(
415414
self._api,
416415
self._cls,
417416
"__replace__",
418417
args=args,
419-
return_type=Instance(self._cls.info, type_vars),
418+
return_type=fill_typevars(self._cls.info),
420419
)
421420

422421
def _add_internal_replace_method(self, attributes: list[DataclassAttribute]) -> None:

test-data/unit/check-python312.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,3 +2084,14 @@ reveal_type(A1().x) # N: Revealed type is "builtins.int"
20842084
reveal_type(A2().x) # N: Revealed type is "builtins.int"
20852085
reveal_type(A3().x) # N: Revealed type is "builtins.list[builtins.int]"
20862086
[builtins fixtures/tuple.pyi]
2087+
2088+
[case testDataclassWithTypeVarTuple]
2089+
# flags: --python-version 3.13
2090+
# https://github.com/python/mypy/issues/19559
2091+
from typing import Callable
2092+
from dataclasses import dataclass
2093+
2094+
@dataclass
2095+
class Test[*Ts, R]:
2096+
a: Callable[[*Ts], R]
2097+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)