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

typish.functions._get_mro.get_mro()   A

Complexity

Conditions 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nop 1
dl 17
loc 17
rs 9.8
c 0
b 0
f 0
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