10000 gh-133925: Make typing._UnionGenericAlias hashable (#133929) · python/cpython@8d478c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d478c7

Browse files
gh-133925: Make typing._UnionGenericAlias hashable (#133929)
1 parent 27ed645 commit 8d478c7

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
@@ -10668,6 +10668,9 @@ def test_eq(self):
1066810668
with self.assertWarns(DeprecationWarning):
1066910669
self.assertNotEqual(int, typing._UnionGenericAlias)
1067010670

10671+
def test_hashable(self):
10672+
self.assertEqual(hash(typing._UnionGenericAlias), hash(Union))
10673+
1067110674

1067210675
def load_tests(loader, tests, pattern):
1067310676
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)
0