gh-133925: Make typing._UnionGenericAlias hashable#133929
gh-133925: Make typing._UnionGenericAlias hashable#133929JelleZijlstra merged 2 commits intopython:mainfrom
Conversation
Lib/typing.py
Outdated
| def __hash__(self): | ||
| return super().__hash__() |
There was a problem hiding this comment.
This means that a Union instance and a _UnionGenericAlias instance might compare equal but hash differently, right? Might that do counterintuitive things if you used them as dictionary keys or put them in sets?
There was a problem hiding this comment.
I think that this is purely about the _UnionGenericAlias class itself, not _UnionGenericAlias instances.
Btw, do we need to add __hash__ tests to instances in other PR?
There was a problem hiding this comment.
I think that this is purely about the
_UnionGenericAliasclass itself, not_UnionGenericAliasinstances.
ah, thanks, great point. It still seems like users are storing the classes themselves in sets, though, so I think my point still applies -- the bug report here comes from astropy/astropy#18126
There was a problem hiding this comment.
Yes, I should have made it hash() equal to Union. Fixed now.
|
Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
GH-133936 is a backport of this pull request to the 3.14 branch. |
typing._UnionGenericAliasis unhashable in 3.14 #133925