mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-44676: Add ability to serialize types.Union (GH-27244)
This commit is contained in:
parent
7d25254cf0
commit
fe13f0b0f6
4 changed files with 90 additions and 2 deletions
|
@ -329,7 +329,7 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()):
|
|||
if isinstance(t, GenericAlias):
|
||||
return GenericAlias(t.__origin__, ev_args)
|
||||
if isinstance(t, types.Union):
|
||||
return functools.reduce(operator.or_, ev_args)
|
||||
return types.Union._from_args(ev_args)
|
||||
else:
|
||||
return t.copy_with(ev_args)
|
||||
return t
|
||||
|
@ -1808,7 +1808,7 @@ def _strip_annotations(t):
|
|||
stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
|
||||
if stripped_args == t.__args__:
|
||||
return t
|
||||
return functools.reduce(operator.or_, stripped_args)
|
||||
return types.Union._from_args(stripped_args)
|
||||
|
||||
return t
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue