class documentation

class TypeAliasType(Type): (source)

View In Hierarchy

A type alias to another type.

NOTE: this is not being used yet, and the implementation is still incomplete.

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 Undocumented
Method _expand​_once Expand to the target type exactly once.
Method _partial​_expansion Undocumented

Inherited from Type:

Method __repr__ Undocumented
Instance Variable can​_be​_false Undocumented
Instance Variable can​_be​_true Undocumented

Inherited from Context (via Type):

Method get​_column Don't use. Use x.column.
Method get​_line Don't use. Use x.line.
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​_line Undocumented
Instance Variable line Undocumented
@classmethod
def deserialize(cls, data): (source)

Undocumented

Parameters
data:JsonDictUndocumented
Returns
TypeAliasTypeUndocumented
def __eq__(self, other): (source)

Undocumented

Parameters
other:objectUndocumented
Returns
boolUndocumented
def __hash__(self): (source)

Undocumented

Returns
intUndocumented
def __init__(self, alias, args, line=-1, column=-1): (source)

Undocumented

Parameters
alias:Optional[mypy.nodes.TypeAlias]Undocumented
args:List[Type]Undocumented
line:intUndocumented
column:intUndocumented
def accept(self, visitor): (source)

Undocumented

Parameters
visitor:TypeVisitor[T]Undocumented
Returns
TUndocumented
def can_be_false_default(self): (source)

Undocumented

Returns
boolUndocumented
def can_be_true_default(self): (source)

Undocumented

Returns
boolUndocumented
def copy_modified(self, *, args=None): (source)

Undocumented

Parameters
args:Optional[List[Type]]Undocumented
Returns
TypeAliasTypeUndocumented
def expand_all_if_possible(self): (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.

Returns
Optional[ProperType]Undocumented
def serialize(self): (source)

Undocumented

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

Undocumented

alias = (source)

Undocumented

args = (source)

Undocumented

type_ref: Optional[str] = (source)

Undocumented

@property
is_recursive: bool = (source)

Undocumented

def _expand_once(self): (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.

Returns
TypeUndocumented
def _partial_expansion(self): (source)

Undocumented

Returns
Tuple[ProperType, bool]Undocumented