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
Why are the type parameters set, frozenset, dict and frozendict are generic in unbounded? #15751
Excuse me if this question may come across as stupid, but these hashed containers should only have hashable items. However, in builtins.pyi, I see that their type variables do not have an upper bound of collections.abc.Hashable. How is that so?
Historically Hashable has been a bit of a problematic type, because hashability is sometimes hard to model (e.g., object is hashable but its subclasses may not be; there is __hash__ = None). Worth trying though and seeing what mypy-primer has to say.
Moreover, this type is not really sound, because some subclasses of hashable types can be unhashable. Or even different instances can differ in hashability :(
True. It would also be exceedingly difficult to make such a big change to builtins.pyi, especially as it would likely involve updating collections.abc as well, and type checkers may have to rework some special casing. Overall, this approach may be infeasible.
Activity
JelleZijlstra commentedon May 10, 2026
Historically Hashable has been a bit of a problematic type, because hashability is sometimes hard to model (e.g., object is hashable but its subclasses may not be; there is
__hash__ = None). Worth trying though and seeing what mypy-primer has to say.jonathandung commentedon May 10, 2026
Should I open a PR?
sobolevn commentedon May 10, 2026
Moreover, this type is not really sound, because some subclasses of hashable types can be unhashable. Or even different instances can differ in hashability :(
jonathandung commentedon May 10, 2026
True. It would also be exceedingly difficult to make such a big change to builtins.pyi, especially as it would likely involve updating collections.abc as well, and type checkers may have to rework some special casing. Overall, this approach may be infeasible.
JelleZijlstra commentedon May 10, 2026
It's worth at least trying and seeing what typeshed's CI has to say.