]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133925: Make typing._UnionGenericAlias hashable (#133929)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Mon, 12 May 2025 15:22:55 +0000 (08:22 -0700)
committerGitHub <noreply@github.com>
Mon, 12 May 2025 15:22:55 +0000 (08:22 -0700)
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 bc03e6bf2d796257948796dfe6c9ab7e4be0366e..6ef633e4545aef3034fbb273089124355fc496fe 100644 (file)
@@ -10668,6 +10668,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 44f39e9672f46b0e2ceff02ce40163e4d26dba14..3d64480e1431c12076a43a71eda4f0c40cf27aa5 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.