typish.functions._get_simple_name   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 66.67 %

Importance

Changes 0
Metric Value
eloc 15
dl 12
loc 18
rs 10
c 0
b 0
f 0
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_simple_name() 12 12 3

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
from functools import lru_cache
2
3
from typish._types import NoneType
4
5
6 View Code Duplication
@lru_cache()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
def get_simple_name(cls: type) -> str:
8
    cls = cls or NoneType
9
    cls_name = getattr(cls, '__name__', None)
10
    if not cls_name:
11
        cls_name = getattr(cls, '_name', None)
12
    if not cls_name:
13
        cls_name = repr(cls)
14
        cls_name = cls_name.split('[')[0]  # Remove generic types.
15
        cls_name = cls_name.split('.')[-1]  # Remove any . caused by repr.
16
        cls_name = cls_name.split(r"'>")[0]  # Remove any '>.
17
    return cls_name
18