Skip to content

mypy doesn't infer __eq__ and __hash__ implementations for dataclasses #19799

@mtsokol

Description

@mtsokol

Bug Report

mypy doesn't infer __eq__ and __hash__ implementations for dataclasses.

To Reproduce

from abc import ABC, abstractmethod
from dataclasses import dataclass


class FType(ABC):
    @abstractmethod
    def __eq__(self, other): ...

    @abstractmethod
    def __hash__(self): ...


@dataclass(eq=True, frozen=True)
class ConcreteType(FType):
    a: int
    b: str


if __name__ == "__main__":

    ct = ConcreteType(1, "b")

    print(ct.__eq__)

Expected Behavior

It should pass.

Actual Behavior

mypy_playground.py:21: error: Cannot instantiate abstract class "ConcreteType" with abstract attributes "__eq__" and "__hash__"  [abstract]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions