$42 GRAYBYTE WORDPRESS FILE MANAGER $48

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 84.32.84.45 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python311/lib/python3.11/site-packages/typish/functions/

HOME
Current File : /opt/alt/python311/lib/python3.11/site-packages/typish/functions//_get_alias.py
import typing
from functools import lru_cache

from typish.functions._is_from_typing import is_from_typing

from typish._types import T


@lru_cache()
def get_alias(cls: T) -> typing.Optional[T]:
    """
    Return the alias from the ``typing`` module for ``cls``. For example, for
    ``cls=list``, the result would be ``typing.List``. If ``cls`` is
    parameterized (>=3.9), then a parameterized ``typing`` equivalent is
    returned. If no alias exists for ``cls``, then ``None`` is returned.
    If ``cls`` already is from ``typing`` it is returned as is.
    :param cls: the type for which the ``typing`` equivalent is to be found.
    :return: the alias from ``typing``.
    """
    if is_from_typing(cls):
        return cls
    alias = _alias_per_type.get(cls.__name__, None)
    if alias:
        args = getattr(cls, '__args__', tuple())
        if args:
            alias = alias[args]
    return alias


_alias_per_type = {
    'list': typing.List,
    'tuple': typing.Tuple,
    'dict': typing.Dict,
    'set': typing.Set,
    'frozenset': typing.FrozenSet,
    'deque': typing.Deque,
    'defaultdict': typing.DefaultDict,
    'type': typing.Type,
    'Set': typing.AbstractSet,
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
8 May 2024 6.34 PM
root / root
0755
__pycache__
--
8 May 2024 6.34 PM
root / root
0755
__init__.py
0 KB
8 May 2024 6.34 PM
root / root
0644
_common_ancestor.py
1.146 KB
8 May 2024 6.34 PM
root / root
0644
_get_alias.py
1.206 KB
8 May 2024 6.34 PM
root / root
0644
_get_args.py
0.421 KB
8 May 2024 6.34 PM
root / root
0644
_get_mro.py
0.919 KB
8 May 2024 6.34 PM
root / root
0644
_get_origin.py
1.126 KB
8 May 2024 6.34 PM
root / root
0644
_get_simple_name.py
0.54 KB
8 May 2024 6.34 PM
root / root
0644
_get_type.py
4.482 KB
8 May 2024 6.34 PM
root / root
0644
_get_type_hints_of_callable.py
1.595 KB
8 May 2024 6.34 PM
root / root
0644
_instance_of.py
1.497 KB
8 May 2024 6.34 PM
root / root
0644
_is_from_typing.py
0.247 KB
8 May 2024 6.34 PM
root / root
0644
_is_optional_type.py
0.633 KB
8 May 2024 6.34 PM
root / root
0644
_is_type_annotation.py
0.855 KB
8 May 2024 6.34 PM
root / root
0644
_subclass_of.py
5.729 KB
8 May 2024 6.34 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF