Total Complexity | 2 |
Total Lines | 31 |
Duplicated Lines | 45.16 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | import typing |
||
2 | from collections import deque, defaultdict, Set |
||
3 | |||
4 | |||
5 | View Code Duplication | def get_origin(t: type) -> type: |
|
|
|||
6 | """ |
||
7 | Return the origin of the given (generic) type. For example, for |
||
8 | ``t=List[str]``, the result would be ``list``. |
||
9 | :param t: the type of which the origin is to be found. |
||
10 | :return: the origin of ``t`` or ``t`` if it is not generic. |
||
11 | """ |
||
12 | from typish.functions._get_simple_name import get_simple_name |
||
13 | |||
14 | simple_name = get_simple_name(t) |
||
15 | result = _type_per_alias.get(simple_name, None) |
||
16 | if not result: |
||
17 | result = getattr(typing, simple_name, t) |
||
18 | return result |
||
19 | |||
20 | |||
21 | _type_per_alias = { |
||
22 | 'List': list, |
||
23 | 'Tuple': tuple, |
||
24 | 'Dict': dict, |
||
25 | 'Set': set, |
||
26 | 'FrozenSet': frozenset, |
||
27 | 'Deque': deque, |
||
28 | 'DefaultDict': defaultdict, |
||
29 | 'Type': type, |
||
30 | 'AbstractSet': Set, |
||
31 | } |
||
32 |