From 89c801b84e4f8d03eb93bae94f49fd9da8d707a4 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 12 May 2025 17:50:10 +0200 Subject: [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 --- Lib/test/test_typing.py | 3 +++ Lib/typing.py | 3 +++ .../NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst | 1 + 3 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-05-12-06-52-10.gh-issue-133925.elInBY.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 8c55ba4..a4fab1d 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -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 diff --git a/Lib/typing.py b/Lib/typing.py index 2baf655..0695a82 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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 index 0000000..328e28a --- /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. -- cgit v0.12