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 |
Undocumented |
Method | can |
Undocumented |
Method | copy |
Undocumented |
Method | expand |
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 |
Undocumented |
Property | is |
Whether this type alias is recursive. |
Method | _expand |
Expand to the target type exactly once. |
Method | _partial |
Undocumented |
Inherited from Type
:
Method | __repr__ |
Undocumented |
Method | can |
Undocumented |
Method | can |
Undocumented |
Method | is |
Undocumented |
Property | can |
Undocumented |
Property | can |
Undocumented |
Instance Variable | _can |
Undocumented |
Instance Variable | _can |
Undocumented |
Inherited from Context
(via Type
):
Method | set |
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 |
Undocumented |
Instance Variable | end |
Undocumented |
Instance Variable | line |
Undocumented |
mypy.nodes.TypeAlias|None
, args: list[ Type]
, line: int
= -1, column: int
= -1):
(source)
¶
mypy.types.Type.__init__
Undocumented
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).
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.