Passed
Pull Request — master (#12)
by Ramon
04:04
created

typish.functions._get_mro   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 77.27 %

Importance

Changes 0
Metric Value
eloc 16
dl 17
loc 22
rs 10
c 0
b 0
f 0
wmc 4

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_mro() 17 17 4

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 inspect import getmro
3
4
5 View Code Duplication
def get_mro(cls: type) -> typing.Tuple[type, ...]:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6
    from typish.functions._get_origin import get_origin
7
8
    # Wrapper around ``getmro`` to allow types from ``Typing``.
9
    if cls is ...:
10
        return Ellipsis, object
11
    elif cls is typing.Union:
12
        # For Python <3.7, we cannot use mro.
13
        super_cls = getattr(typing, '_GenericAlias',
14
                            getattr(typing, 'GenericMeta', None))
15
        return (typing.Union, super_cls, object)
16
17
    origin = get_origin(cls)
18
    if origin != cls:
19
        return get_mro(origin)
20
21
    return getmro(cls)
22