class documentation

class TypeAliasType(Type): (source)

View In Hierarchy

A type alias to another type. To support recursive type aliases we don't immediately expand a type alias during semantic analysis, but create an instance of this type that records the target alias definition node (mypy.nodes.TypeAlias) and type arguments (for generic aliases). This is very similar to how TypeInfo vs Instance interact, where a recursive class-based structure like class Node: value: int children: List[Node] can be represented in a tree-like manner.

Class Method deserialize Undocumented
Method __eq__ Undocumented
Method __hash__ Undocumented
Method __init__ Undocumented
Method accept Undocumented
Method can_be_false_default Undocumented
Method can_be_true_default Undocumented
Method copy_modified Undocumented
Method expand_all_if_possible Attempt a full expansion of the type alias (including nested aliases).
Method serialize Undocumented
Class Variable __slots__ Undocumented
Instance Variable alias Undocumented
Instance Variable args Undocumented
Instance Variable type_ref Undocumented
Property is_recursive Whether this type alias is recursive.
Method _expand_once Expand to the target type exactly once.
Method _partial_expansion Undocumented

Inherited from Type:

Method __repr__ Undocumented
Method can_be_false.setter Undocumented
Method can_be_true.setter Undocumented
Method is_singleton_type Undocumented
Property can_be_false Undocumented
Property can_be_true Undocumented
Instance Variable _can_be_false Undocumented
Instance Variable _can_be_true Undocumented

Inherited from Context (via Type):

Method set_line If target is a node, pull line (and column) information into this node. If column is specified, this will override any column information coming from a node.
Instance Variable column Undocumented
Instance Variable end_column Undocumented
Instance Variable end_line Undocumented
Instance Variable line Undocumented
@classmethod
def deserialize(cls, data: JsonDict) -> TypeAliasType: (source)

Undocumented

def __eq__(self, other: object) -> bool: (source)

Undocumented

def __hash__(self) -> int: (source)

Undocumented

def __init__(self, alias: mypy.nodes.TypeAlias|None, args: list[Type], line: int = -1, column: int = -1): (source)

Undocumented

def accept(self, visitor: TypeVisitor[T]) -> T: (source)

Undocumented

def can_be_false_default(self) -> bool: (source)

Undocumented

def can_be_true_default(self) -> bool: (source)

Undocumented

def copy_modified(self, *, args: list[Type]|None = None) -> TypeAliasType: (source)

Undocumented

def expand_all_if_possible(self, nothing_args: bool = False) -> ProperType|None: (source)

Attempt a full expansion of the type alias (including nested aliases). If the expansion is not possible, i.e. the alias is (mutually-)recursive, return None. If nothing_args is True, replace all type arguments with an UninhabitedType() (used to detect recursively defined aliases).

def serialize(self) -> JsonDict: (source)

Undocumented

__slots__: tuple[str, ...] = (source)

Undocumented

Undocumented

Undocumented

Undocumented

@property
is_recursive: bool = (source)

Whether this type alias is recursive. Note this doesn't check generic alias arguments, but only if this alias *definition* is recursive. The property value thus can be cached on the underlying TypeAlias node. If you want to include all nested types, use has_recursive_types() function.

def _expand_once(self) -> Type: (source)

Expand to the target type exactly once. This doesn't do full expansion, i.e. the result can contain another (or even this same) type alias. Use this internal helper only when really needed, its public wrapper mypy.types.get_proper_type() is preferred.

def _partial_expansion(self, nothing_args: bool = False) -> tuple[ProperType, bool]: (source)

Undocumented