| Total Complexity | 1 | 
| Total Lines | 29 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | import typing | ||
| 2 | from functools import lru_cache | ||
| 3 | |||
| 4 | from typish._types import T | ||
| 5 | |||
| 6 | |||
| 7 | @lru_cache() | ||
| 8 | def get_alias(cls: T) -> typing.Optional[T]: | ||
| 9 | """ | ||
| 10 | Return the alias from the ``typing`` module for ``cls``. For example, for | ||
| 11 | ``cls=list``, the result would be ``typing.List``. If no alias exists for | ||
| 12 | ``cls``, then ``None`` is returned. | ||
| 13 | :param cls: the type for which the ``typing`` equivalent is to be found. | ||
| 14 | :return: the alias from ``typing``. | ||
| 15 | """ | ||
| 16 | return _alias_per_type.get(cls.__name__, None) | ||
| 17 | |||
| 18 | |||
| 19 | _alias_per_type = { | ||
| 20 | 'list': typing.List, | ||
| 21 | 'tuple': typing.Tuple, | ||
| 22 | 'dict': typing.Dict, | ||
| 23 | 'set': typing.Set, | ||
| 24 | 'frozenset': typing.FrozenSet, | ||
| 25 | 'deque': typing.Deque, | ||
| 26 | 'defaultdict': typing.DefaultDict, | ||
| 27 | 'type': typing.Type, | ||
| 28 | 'Set': typing.AbstractSet, | ||
| 29 | } | ||
| 30 |