https://github.com/python/cpython/commit/89c801b84e4f8d03eb93bae94f49fd9da8d707a4
commit: 89c801b84e4f8d03eb93bae94f49fd9da8d707a4
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2025-05-12T15:50:10Z
summary:

[3.14] gh-133925: Make typing._UnionGenericAlias hashable (GH-133929) (#133936)

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

Co-authored-by: Jelle Zijlstra <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst
M Lib/test/test_typing.py
M Lib/typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 8c55ba4623e719..a4fab1d5e14805 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -10731,6 +10731,9 @@ def test_eq(self):
         with self.assertWarns(DeprecationWarning):
             self.assertNotEqual(int, typing._UnionGenericAlias)
 
+    def test_hashable(self):
+        self.assertEqual(hash(typing._UnionGenericAlias), hash(Union))
+
 
 def load_tests(loader, tests, pattern):
     import doctest
diff --git a/Lib/typing.py b/Lib/typing.py
index 2baf655256d1eb..0695a825283c7a 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1649,6 +1649,9 @@ def __eq__(self, other):
             return True
         return NotImplemented
 
+    def __hash__(self):
+        return hash(Union)
+
 
 class _UnionGenericAlias(metaclass=_UnionGenericAliasMeta):
     """Compatibility hack.
diff --git 
a/Misc/NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst 
b/Misc/NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst
new file mode 100644
index 00000000000000..328e28abc3b42b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst
@@ -0,0 +1 @@
+Make the private class ``typing._UnionGenericAlias`` hashable.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to