Open
Description
Bug Report
MyPy doesn't seem to understand that dataclasses can generate an __eq__
method. If it's required (such as in an ABC), then it doesn't know that it was created.
To Reproduce
import dataclasses
import abc
@dataclasses.dataclass(eq=False)
class AbstractEq(abc.ABC):
@abc.abstractmethod
def __eq__(self, other: object) -> bool:
pass
@dataclasses.dataclass
class ConcreteEq(AbstractEq):
x: int
print(ConcreteEq(1) == ConcreteEq(1))
Gist URL: https://gist.github.com/89d988a5c8d37bd10d17445d5e344e63
Playground URL: https://mypy-play.net/?mypy=latest&python=3.10&gist=89d988a5c8d37bd10d17445d5e344e63
Expected Behavior
This should pass. It does at runtime. dataclasses do add __eq__
unless eq=False
.
Actual Behavior
main.py:14: error: Cannot instantiate abstract class "ConcreteEq" with abstract attribute "__eq__"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.981 (playground) and 0.982 (local)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10
I didn't see any other issues that were exactly this issue.