Skip to content

fix: prevent crash on dataclass with PEP695 TypeVarTuple on py3.13 #19565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,12 @@ def _add_dunder_replace(self, attributes: list[DataclassAttribute]) -> None:
for attr in attributes
if attr.is_in_init
]
type_vars = [tv for tv in self._cls.type_vars]
add_method_to_class(
self._api,
self._cls,
"__replace__",
args=args,
return_type=Instance(self._cls.info, type_vars),
return_type=fill_typevars(self._cls.info),
)

def _add_internal_replace_method(self, attributes: list[DataclassAttribute]) -> None:
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2084,3 +2084,14 @@ reveal_type(A1().x) # N: Revealed type is "builtins.int"
reveal_type(A2().x) # N: Revealed type is "builtins.int"
reveal_type(A3().x) # N: Revealed type is "builtins.list[builtins.int]"
[builtins fixtures/tuple.pyi]

[case testDataclassWithTypeVarTuple]
# flags: --python-version 3.13
# https://github.com/python/mypy/issues/19559
from typing import Callable
from dataclasses import dataclass

@dataclass
class Test[*Ts, R]:
a: Callable[[*Ts], R]
[builtins fixtures/dict.pyi]
Loading