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 |
mypy.types.Type.deserialize
Undocumented
Parameters | |
data:JsonDict | Undocumented |
Returns | |
TypeAliasType | Undocumented |
mypy.types.Type.__init__
Undocumented
Parameters | |
alias:Optional[ | Undocumented |
args:List[ | Undocumented |
line:int | Undocumented |
column:int | Undocumented |
mypy.types.Type.accept
Undocumented
Parameters | |
visitor:TypeVisitor[ | Undocumented |
Returns | |
T | 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.
Returns | |
Optional[ | Undocumented |
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 | |
Type | Undocumented |