Skip to content

typing._UnionGenericAlias is unhashable in 3.14 #133925

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

Closed
neutrinoceros opened this issue May 12, 2025 · 5 comments
Closed

typing._UnionGenericAlias is unhashable in 3.14 #133925

neutrinoceros opened this issue May 12, 2025 · 5 comments
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@neutrinoceros
Copy link
Contributor

neutrinoceros commented May 12, 2025

Bug report

Bug description:

typing._UnionGenericAlias) became unshable somewhere between 3.13 and 3.14.0b1 (most likely in gh-105511)

import typing
hash(typing._UnionGenericAlias)
Traceback (most recent call last):
  File "<python-input-0>", line 2, in <module>
    hash(typing._UnionGenericAlias)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: '_UnionGenericAliasMeta'

This was hit in a doctest from astropy: xref astropy/astropy#18126
To be clear, the test in question doesn't necessarily correspond to a real-life application; we're testing that our itersubclasses utility function works in a very broad case where we try to retrieve all defined subclasses of object, and do a bit of internal book-keeping using a set of already-visited classes. This used to work in Python 3.13 (and seems to have worked with no interruption for 10+ years), so it still seemed worth a shot to see if that would be considered a bug here. Otherwise, it should be possible to fix the function on our side to either special case this exact class, ignore any unhashable class, or avoid reequiring hashability altogether.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

@hugovk
Copy link
Member

hugovk commented May 12, 2025

(most likely in gh-105511)

Git bisect agrees, cc @JelleZijlstra.

@JelleZijlstra
Copy link
Member

It's because I added __eq__ but not __hash__ to the metaclass. Fix in #133929.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 12, 2025
JelleZijlstra added a commit that referenced this issue May 12, 2025
…#133936)

gh-133925: Make typing._UnionGenericAlias hashable (GH-133929)
(cherry picked from commit 8d478c7)

Co-authored-by: Jelle Zijlstra <[email protected]>
@neutrinoceros
Copy link
Contributor Author

Is there a reason to keep this open after the fox was merged ?

@AlexWaygood
Copy link
Member

AlexWaygood commented May 12, 2025

no, this is done now that the 🦊 is merged

@neutrinoceros
Copy link
Contributor Author

Thanks, all !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants