Open
Description
For a class decorated with @dataclass
, mypy assumes that the class's __eq__
method will have the exact same signature as object.__eq__
. However, this is subtly incorrect. Whereas the signature of object.__eq__
is def __eq__(self, other: object, /) -> bool: ...
, the signature of MyDataclass.__eq__
is def __eq__(self, other: object) -> bool: ...
. I.e., for the method auto-generated by @dataclass
, the second argument is positional-or-keyword; whereas the second argument is positional-only for object.__eq__
.
Minimal repro (using mypy 0.931, Python 3.10 -- try it on mypy playground here):
from dataclasses import dataclass
@dataclass
class Foo: ...
reveal_type(Foo.__eq__) # Revealed type is "def (builtins.object, builtins.object) -> builtins.bool"