| Conditions | 5 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 27 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | import typing |
||
| 5 | View Code Duplication | def get_mro(obj: typing.Any) -> typing.Tuple[type, ...]: |
|
|
|
|||
| 6 | """ |
||
| 7 | Return tuple of base classes (including that of obj) in method resolution |
||
| 8 | order. Types from typing are supported as well. |
||
| 9 | :param obj: object or type. |
||
| 10 | :return: a tuple of base classes. |
||
| 11 | """ |
||
| 12 | from typish.functions._get_origin import get_origin |
||
| 13 | |||
| 14 | # Wrapper around ``getmro`` to allow types from ``typing``. |
||
| 15 | if obj is ...: |
||
| 16 | return Ellipsis, object |
||
| 17 | elif obj is typing.Union: |
||
| 18 | # For Python <3.7, we cannot use mro. |
||
| 19 | super_cls = getattr(typing, '_GenericAlias', |
||
| 20 | getattr(typing, 'GenericMeta', None)) |
||
| 21 | return typing.Union, super_cls, object |
||
| 22 | |||
| 23 | origin = get_origin(obj) |
||
| 24 | if origin != obj: |
||
| 25 | return get_mro(origin) |
||
| 26 | |||
| 27 | cls = obj |
||
| 28 | if not isinstance(obj, type): |
||
| 29 | cls = type(obj) |
||
| 30 | |||
| 31 | return getmro(cls) |
||
| 32 |