bpo-44676: Serialize the union type using only public API (GH-27323)

Remove also the _from_args() constructor.
This commit is contained in:
Serhiy Storchaka 2021-07-24 21:26:02 +03:00 committed by GitHub
parent 4f5980a4f5
commit 435a0334d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 79 deletions

View file

@ -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 types.Union._from_args(ev_args)
return functools.reduce(operator.or_, ev_args)
else:
return t.copy_with(ev_args)
return t
@ -1814,7 +1814,7 @@ def _strip_annotations(t):
stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
if stripped_args == t.__args__:
return t
return types.Union._from_args(stripped_args)
return functools.reduce(operator.or_, stripped_args)
return t