Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 89c801b

Browse files
miss-islingtonJelleZijlstra
andauthoredMay 12, 2025··
[3.14] gh-133925: Make typing._UnionGenericAlias hashable (GH-133929) (#133936)
gh-133925: Make typing._UnionGenericAlias hashable (GH-133929) (cherry picked from commit 8d478c7) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent ecc12bf commit 89c801b

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed
 

‎Lib/test/test_typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10731,6 +10731,9 @@ def test_eq(self):
1073110731
with self.assertWarns(DeprecationWarning):
1073210732
self.assertNotEqual(int, typing._UnionGenericAlias)
1073310733

10734+
def test_hashable(self):
10735+
self.assertEqual(hash(typing._UnionGenericAlias), hash(Union))
10736+
1073410737

1073510738
def load_tests(loader, tests, pattern):
1073610739
import doctest

‎Lib/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,9 @@ def __eq__(self, other):
16491649
return True
16501650
return NotImplemented
16511651

1652+
def __hash__(self):
1653+
return hash(Union)
1654+
16521655

16531656
class _UnionGenericAlias(metaclass=_UnionGenericAliasMeta):
16541657
"""Compatibility hack.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make the private class ``typing._UnionGenericAlias`` hashable.

0 commit comments

Comments
 (0)
Please sign in to comment.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant