]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-133925: Make typing._UnionGenericAlias hashable (GH-133929) (#133936)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 12 May 2025 15:50:10 +0000 (17:50 +0200)
committerGitHub <noreply@github.com>
Mon, 12 May 2025 15:50:10 +0000 (15:50 +0000)
gh-133925: Make typing._UnionGenericAlias hashable (GH-133929)
(cherry picked from commit 8d478c79539ed0ec7071766b7a0afe62fb11f7d4)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst [new file with mode: 0644]

index 8c55ba4623e719153430d59ef1e50df73056d981..a4fab1d5e148054e4fc253f75ad06cf5c0cec536 100644 (file)
@@ -10731,6 +10731,9 @@ class UnionGenericAliasTests(BaseTestCase):
         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
index 2baf655256d1eb7f3967366832d21b45ee022b9c..0695a825283c7aad03ecb46420a35bfd7709d520 100644 (file)
@@ -1649,6 +1649,9 @@ class _UnionGenericAliasMeta(type):
             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 (file)
index 0000000..328e28a
--- /dev/null
@@ -0,0 +1 @@
+Make the private class ``typing._UnionGenericAlias`` hashable.