Skip to content

Commit 89c801b

Browse files
[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 <[email protected]>
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

+3
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

+3
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make the private class ``typing._UnionGenericAlias`` hashable.

0 commit comments

Comments
 (0)