| Conditions | 6 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 10 | def get_class_name(cls: type, |
||
| 11 | transformer: Optional[Callable[[str], str]] = None) \ |
||
| 12 | -> Optional[str]: |
||
| 13 | """ |
||
| 14 | Return the name of a class. |
||
| 15 | :param cls: the class of which the name if to be returned. |
||
| 16 | :param transformer: any string transformer, e.g. ``str.lower``. |
||
| 17 | :return: the name of ``cls``, transformed if a transformer is given. |
||
| 18 | """ |
||
| 19 | cls_name = getattr(cls, '__name__', getattr(cls, '_name', None)) |
||
| 20 | if not cls_name and hasattr(cls, '__origin__'): |
||
| 21 | origin = cls.__origin__ |
||
| 22 | cls_name = get_class_name(origin) |
||
| 23 | if not cls_name: |
||
| 24 | cls_name = str(cls) |
||
| 25 | if cls_name and transformer: |
||
| 26 | cls_name = transformer(cls_name) |
||
| 27 | return cls_name |
||
| 28 | |||
| 46 |