Passed
Push — master ( c3c399...6aa0ae )
by Ramon
55s queued 10s
created

typish.functions._get_origin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 45.16 %

Importance

Changes 0
Metric Value
eloc 20
dl 14
loc 31
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_origin() 14 14 2

How to fix   Duplicated Code   

Duplicated Code

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:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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