Fix regression in dataclass narrowing for Python >= 3.13 (#21675)
Fixes #21635 On Python >= 3.13, `@dataclass` synthesizes a `__replace__(self, ...) -> Self` method to support `copy.replace()`. When mypy tries to narrow a `type[A]` expression via `issubclass(cls, M)` (or `isinstance`) against a second, unrelated dataclass `M`, it builds an ad-hoc `<subclass of A and M>` type to check whether that narrowing is sound (`intersect_instances` in `checker.py`). Building that ad-hoc type runs `check_multiple_inheritance`, which sees `A`'s synthesized `__replace__` returning `A` and `M`'s returning `M`, and flags them as incompatible. That's a false positive: a real subclass of both (e.g. `class C(M, A)`, itself decorated with `@dataclass`) gets its *own* freshly synthesized, mutually compatible `__replace__`.
Y
ygale committed
b6d93f5a26abcb8554d9938b162ce3eda74b4ea8
Parent: e986558
Committed by GitHub <noreply@github.com>
on 7/7/2026, 7:54:01 PM