Skip to content
Open
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
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ class C(B, A[int]): ... # this is unsafe because...
x: A[int] = C()
x.foo # ...runtime type is (str) -> None, while static type is (int) -> None
"""
if name in ("__init__", "__new__", "__init_subclass__"):
if name in {"__init__", "__new__", "__init_subclass__", "__replace__"}:
# __init__ and friends can be incompatible -- it's a special case.
return
first = base1.names[name]
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,27 @@ class Y(X):
[builtins fixtures/tuple.pyi]


[case testDunderReplaceDoesNotBlockPlainIssubclassNarrowing]
# https://github.com/python/mypy/issues/21635
# flags: --python-version 3.13
from dataclasses import dataclass

@dataclass
class A: ...
@dataclass
class M: ...
@dataclass
class B(A): ...
@dataclass
class C(M, A): ...

cls: type[A] = C
if issubclass(cls, M):
reveal_type(cls) # N: Revealed type is "type[__main__.<subclass of "__main__.A" and "__main__.M">]"
n: int = 'foo' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
[builtins fixtures/isinstancelist.pyi]


[case testFrozenWithFinal]
from dataclasses import dataclass
from typing import Final
Expand Down
Loading