You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dataclasses that are hashable (e.g. frozen=True) that extend any abc/protocol requiring __hash__ (e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to be instantiated.
In addition to frozen=True/Hashable, you also get the same error with unsafe_hash=True, as well as using your own protocol or abc that requires __hash__.
No, there's no distinction between plugin-generated and regular methods for this check. is_abstract is set after semanal, so plugin should have already been called at that point.
This problem is more obvious: mypy does not generate __hash__ on dataclasses at all. At least grepping for hash finds no matches in dataclass plugin code. A is accepted because we have object.__hash__, so A is indeed hashable from mypy perspective. B explicitly inherits from Hashable and thus Hashable.__hash__ is the highest MRO entry, and it's abstract.
Probably we should just generate __hash__ on dataclasses. This should be easy to do, dunder-hash is simple and non-generic.
Bug Report
Dataclasses that are hashable (e.g.
frozen=True
) that extend any abc/protocol requiring__hash__
(e.g. collections.abc.Hashable) is considered abstract and gives an error when trying to be instantiated.In addition to
frozen=True
/Hashable
, you also get the same error withunsafe_hash=True
, as well as using your own protocol or abc that requires__hash__
.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=390504f01055e489b12b388eec1de256
Expected Behavior
This works at runtime -- running the script prints the hash, demonstrating that it has
__hash__
defined.Actual Behavior
Your Environment
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: