MCPcopy Index your code
hub / github.com/python/mypy / PlaceholderNode

Class PlaceholderNode

mypy/nodes.py:4709–4780  ·  view source on GitHub ↗

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 mo

Source from the content-addressed store, hash-verified

4707
4708
4709class PlaceholderNode(SymbolNode):
4710 """Temporary symbol node that will later become a real SymbolNode.
4711
4712 These are only present during semantic analysis when using the new
4713 semantic analyzer. These are created if some essential dependencies
4714 of a definition are not yet complete.
4715
4716 A typical use is for names imported from a module which is still
4717 incomplete (within an import cycle):
4718
4719 from m import f # Initially may create PlaceholderNode
4720
4721 This is particularly important if the imported shadows a name from
4722 an enclosing scope or builtins:
4723
4724 from m import int # Placeholder avoids mixups with builtins.int
4725
4726 Another case where this is useful is when there is another definition
4727 or assignment:
4728
4729 from m import f
4730 def f() -> None: ...
4731
4732 In the above example, the presence of PlaceholderNode allows us to
4733 handle the second definition as a redefinition.
4734
4735 They are also used to create PlaceholderType instances for types
4736 that refer to incomplete types. Example:
4737
4738 class C(Sequence[C]): ...
4739
4740 We create a PlaceholderNode (with becomes_typeinfo=True) for C so
4741 that the type C in Sequence[C] can be bound.
4742
4743 Attributes:
4744
4745 fullname: Full name of the PlaceholderNode.
4746 node: AST node that contains the definition that caused this to
4747 be created. This is useful for tracking order of incomplete definitions
4748 and for debugging.
4749 becomes_typeinfo: If True, this refers something that could later
4750 become a TypeInfo. It can't be used with type variables, in
4751 particular, as this would cause issues with class type variable
4752 detection.
4753
4754 The long-term purpose of placeholder nodes/types is to evolve into
4755 something that can support general recursive types.
4756 """
4757
4758 __slots__ = ("_fullname", "node", "becomes_typeinfo")
4759
4760 def __init__(
4761 self, fullname: str, node: Node, line: int, *, becomes_typeinfo: bool = False
4762 ) -> None:
4763 self._fullname = fullname
4764 self.node = node
4765 self.becomes_typeinfo = becomes_typeinfo
4766 self.line = line

Callers 4

analyze_classMethod · 0.90
mark_incompleteMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…