PyDocs

Nav

Development Tools

TypeAliasType

typing

class · Added in 3.12
  • TypeAliasType(name, value, *, type_params=(), qualname=None)
Type alias.

Type aliases are created through the type statement::

    type Alias = int

In this example, Alias and int will be treated equivalently by static
type checkers.

At runtime, Alias is an instance of TypeAliasType. The __name__
attribute holds the name of the type alias. The value of the type alias
is stored in the __value__ attribute. It is evaluated lazily, so the
value is computed only if the attribute is accessed. The __module__
attribute holds the name of the module in which the type alias was
defined; it can be assigned to.

Type aliases can also be generic::

    type ListOrSet[T] = list[T] | set[T]

In this case, the type parameters of the alias are stored in the
__type_params__ attribute.

See PEP 695 for more information.
Members of TypeAliasType

_

__module__
The name of the module in which the type alias was defined:
__name__
The name of the type alias:
__qualname__
The qualified name of the type alias:
__type_params__
The type parameters of the type alias, or an empty tuple if the alias is not generic:
__value__
The type alias’s value.

e

evaluate_value
An evaluate function corresponding to the __value__ attribute.
1 Example
>>> type Alias = int
>>> type(Alias)
<class 'typing.TypeAliasType'>
from the Python docs
See Also
No see-alsos for typing/TypeAliasType
0 Notes
No notes for TypeAliasType