File: py314-get-origin-union.patch

package info (click to toggle)
python-typing-inspect 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 300 kB
  • sloc: python: 3,179; sh: 8; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From: Leon Barrett <Leon.Barrett@sony.com>
Date: Fri, 16 Jan 2026 17:15:38 -0800
Subject: Support `get_origin(Union[...])` in python 3.14

In Python 3.14, `Union` is no longer a `typingGenericAlias`, so
`get_origin(int | str)` didn't return `Union`. This changes that by
explicitly checking for `is_union_type`. This adds a test for
`get_origin(Union[...])`.

Origin: upstream, https://github.com/ilevkivskyi/typing_inspect/pull/119
Bug-Debian: https://bugs.debian.org/1123326
Last-Update: 2026-02-16
---
 test_typing_inspect.py | 1 +
 typing_inspect.py      | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/test_typing_inspect.py b/test_typing_inspect.py
index df7ed36..4d88378 100644
--- a/test_typing_inspect.py
+++ b/test_typing_inspect.py
@@ -355,6 +355,7 @@ class GetUtilityTestCase(TestCase):
         if GENERIC_TUPLE_PARAMETRIZABLE:
             tp = List[Tuple[T, T]][int]
             self.assertEqual(get_origin(tp), list if NEW_TYPING else List)
+        self.assertIs(get_origin(Union[str, int]), typing.Union)
 
     def test_parameters(self):
         T = TypeVar('T')
diff --git a/typing_inspect.py b/typing_inspect.py
index 7605026..b7da0dd 100644
--- a/typing_inspect.py
+++ b/typing_inspect.py
@@ -359,7 +359,13 @@ def get_origin(tp):
         get_origin(List[Tuple[T, T]][int]) == list  # List prior to Python 3.7
     """
     if NEW_TYPING:
-        if isinstance(tp, typingGenericAlias):
+        if (
+            isinstance(tp, typingGenericAlias) or
+            # In Python 3.14, Union[...] is not an instance of
+            # typingGenericAlias, but it does have an `__origin__`, so check for
+            # Unions explicitly.
+            is_union_type(tp)
+        ):
             return tp.__origin__ if tp.__origin__ is not ClassVar else None
         if tp is Generic:
             return Generic