Skip to content

@dataclass does not handle __hash__: None special case #11495

Open
@sobolevn

Description

@sobolevn

While working on #11463 I found that adding __hash__: None annotations does not work correctly.

Mypy says:

from dataclasses import dataclass

@dataclass(unsafe_hash=False, eq=True, frozen=False)
class SecondCase2:
    x: int
    __hash__: None  # E: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[object], int]")
print(SecondCase2(1).__hash__)  # N: Revealed type is "None" \
                                                      # E: Missing positional argument "__hash__" in call to "SecondCase2"

It looks like __hash__ is added to fields and __init__. While runtime version works just fine:

» python out/ex.py
SecondCase2(x=1, __hash__=<slot wrapper '__hash__' of 'object' objects>)

I will fix it in the same PR as #11463

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions