Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sobolevn opened this issue Nov 8, 2021 · 0 comments · May be fixed by #13187
Open

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

sobolevn opened this issue Nov 8, 2021 · 0 comments · May be fixed by #13187
Labels
bug mypy got something wrong topic-dataclasses

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-dataclasses
Projects
None yet
2 participants