Skip to content

Commit 0bacb41

Browse files
committed
Simplify the implementation of the Union type and remove recursion avoidance logic.
1 parent 78e8785 commit 0bacb41

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

Lib/typing.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -787,18 +787,9 @@ def Union(self, parameters):
787787
def _union_from_types(left, right):
788788
"""Helper function to create union types avoiding recursion."""
789789
try:
790-
if hasattr(left, '__or__') and not isinstance(left, _GenericAlias):
791-
return left | right
792-
elif hasattr(right, '__ror__') and not isinstance(right, _GenericAlias):
793-
return right.__ror__(left)
794-
else:
795-
if hasattr(left, '__origin__'):
796-
left = left.__origin__
797-
if hasattr(right, '__origin__'):
798-
right = right.__origin__
799-
return left | right
790+
return left | right
800791
except (TypeError, AttributeError):
801-
return f"Union[{left}, {right}]"
792+
return Union[left, right]
802793

803794

804795
@_SpecialForm

0 commit comments

Comments
 (0)