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
{{ message }}
Repository navigation
dataclasses with generated __hash__ subclassing Hashable are considered abstract #18962
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.
Activity
A5rocks commentedon Apr 24, 2025
More generally:
I suspect this is that mypy doesn't check what methods a plugin adds when looking at whether a class is abstract.
sterliakov commentedon Apr 25, 2025
No, there's no distinction between plugin-generated and regular methods for this check.
is_abstractis set after semanal, so plugin should have already been called at that point.This problem is more obvious:
mypydoes not generate__hash__on dataclasses at all. At least grepping forhashfinds no matches in dataclass plugin code.Ais accepted because we haveobject.__hash__, soAis indeed hashable from mypy perspective.Bexplicitly inherits fromHashableand thusHashable.__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.