Conditions | 4 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 17 |
Ratio | 100 % |
Changes | 0 |
1 | import typing |
||
9 | View Code Duplication | def get_origin(t: type) -> type: |
|
|
|||
10 | """ |
||
11 | Return the origin of the given (generic) type. For example, for |
||
12 | ``t=List[str]``, the result would be ``list``. |
||
13 | :param t: the type of which the origin is to be found. |
||
14 | :return: the origin of ``t`` or ``t`` if it is not generic. |
||
15 | """ |
||
16 | from typish.functions._get_simple_name import get_simple_name |
||
17 | |||
18 | simple_name = get_simple_name(t) |
||
19 | result = _type_per_alias.get(simple_name, None) |
||
20 | if isclass(t) and not is_from_typing(t): |
||
21 | # Get the origin in case of a parameterized generic. |
||
22 | result = getattr(t, '__origin__', t) |
||
23 | elif not result: |
||
24 | result = getattr(typing, simple_name, t) |
||
25 | return result |
||
26 | |||
40 |