Skip to content

Commit

Permalink
fix: get_origin for generic Union in 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Mar 13, 2021
1 parent fd10f52 commit d603d16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/test_typing_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_get_args(tp, expected_args):
(Generic, Generic),
(Generic[T], Generic),
(Union[T, int], Union),
(Union[T, int][str], Union),
(List[Tuple[T, T]][int], list),
(StrangePair[int, str], StrangePair),
(Callable, collections.abc.Callable),
Expand Down
9 changes: 5 additions & 4 deletions typingx/typing_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ def T_get_origin(tp: TypeLike) -> T.Optional[TypeLike]:
T.Type: type,
}

if hasattr(tp, "_gorg"):
origin = tp._gorg
else:
origin = getattr(tp, "__origin__", None)
origin = getattr(tp, "_gorg", getattr(tp, "__origin__", None))

while getattr(origin, "__args__", None):
origin = T_get_origin(origin)

return typing_to_builtin_map.get(origin, origin)


Expand Down

0 comments on commit d603d16

Please sign in to comment.