summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>2020-12-29 02:26:19 (GMT)
committerGitHub <noreply@github.com>2020-12-29 02:26:19 (GMT)
commitefb1f0918fad2ba3346a986b0e958dc5753a7bbe (patch)
tree035a6ce4a6e3778e74a68ee6ea614190e20811e7 /Lib/typing.py
parenta6d63a20df63b3fd33b5e1f629e7f96d00f6ae39 (diff)
downloadcpython-efb1f0918fad2ba3346a986b0e958dc5753a7bbe.zip
cpython-efb1f0918fad2ba3346a986b0e958dc5753a7bbe.tar.gz
cpython-efb1f0918fad2ba3346a986b0e958dc5753a7bbe.tar.bz2
bpo-42740: Support PEP 604, 612 for typing.py get_args and get_origin (GH-23942)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 67e95dd..d1db76f 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1668,6 +1668,8 @@ def get_origin(tp):
return tp.__origin__
if tp is Generic:
return Generic
+ if isinstance(tp, types.Union):
+ return types.Union
return None
@@ -1686,9 +1688,13 @@ def get_args(tp):
return (tp.__origin__,) + tp.__metadata__
if isinstance(tp, (_GenericAlias, GenericAlias)):
res = tp.__args__
- if tp.__origin__ is collections.abc.Callable and res[0] is not Ellipsis:
+ if (tp.__origin__ is collections.abc.Callable
+ and not (res[0] is Ellipsis
+ or isinstance(res[0], (ParamSpec, _ConcatenateGenericAlias)))):
res = (list(res[:-1]), res[-1])
return res
+ if isinstance(tp, types.Union):
+ return tp.__args__
return ()