class PlaceholderNode(SymbolNode): (source)
Temporary symbol node that will later become a real SymbolNode.
These are only present during semantic analysis when using the new semantic analyzer. These are created if some essential dependencies of a definition are not yet complete.
A typical use is for names imported from a module which is still incomplete (within an import cycle):
from m import f # Initially may create PlaceholderNode
This is particularly important if the imported shadows a name from an enclosing scope or builtins:
from m import int # Placeholder avoids mixups with builtins.int
Another case where this is useful is when there is another definition or assignment:
from m import f def f() -> None: ...
In the above example, the presence of PlaceholderNode allows us to handle the second definition as a redefinition.
They are also used to create PlaceholderType instances for types that refer to incomplete types. Example:
class C(Sequence[C]): ...
We create a PlaceholderNode (with becomes_typeinfo=True) for C so that the type C in Sequence[C] can be bound.
Attributes:
fullname: Full name of of the PlaceholderNode. node: AST node that contains the definition that caused this to
be created. This is useful for tracking order of incomplete definitions and for debugging.
- becomes_typeinfo: If True, this refers something that could later
- become a TypeInfo. It can't be used with type variables, in particular, as this would cause issues with class type variable detection.
The long-term purpose of placeholder nodes/types is to evolve into something that can support general recursive types.
Method | __init__ |
Undocumented |
Method | accept |
Undocumented |
Method | serialize |
Undocumented |
Class Variable | __slots__ |
Undocumented |
Instance Variable | becomes_typeinfo |
Undocumented |
Instance Variable | line |
Undocumented |
Instance Variable | node |
Undocumented |
Property | fullname |
Undocumented |
Property | name |
Undocumented |
Instance Variable | _fullname |
Undocumented |
Inherited from SymbolNode
:
Class Method | deserialize |
Undocumented |
Inherited from Node
(via SymbolNode
):
Method | __str__ |
Undocumented |
Inherited from Context
(via SymbolNode
, Node
):
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 |
mypy.nodes.Context.__init__
Undocumented
Parameters | |
fullname:str | Undocumented |
node:Node | Undocumented |
line:int | Undocumented |
becomes_typeinfo:bool | Undocumented |
mypy.nodes.Node.accept
Undocumented
Parameters | |
visitor:NodeVisitor[ | Undocumented |
Returns | |
T | Undocumented |