InferenceContext¶
- class astroid.context.InferenceContext(path: set[tuple[nodes.NodeNG, str | None]] | None = None, nodes_inferred: list[int] | None = None)[source]¶
Bases:
objectProvide context for inference.
Store already inferred nodes to save time Account for already visited nodes to stop infinite recursion
- boundnode: SuccessfulInferenceResult | None¶
The bound node of the given context.
e.g. the bound node of object.__new__(cls) is the object node
- callcontext: CallContext | None¶
The call arguments and keywords for the given context.
- clone() InferenceContext[source]¶
Clone inference path.
For example, each side of a binary operation (BinOp) starts with the same context but diverge as each side is inferred so the InferenceContext will need be cloned
- extra_context: dict[SuccessfulInferenceResult, InferenceContext]¶
Context that needs to be passed down through call stacks for call arguments.
- property inferred: _InferenceCache¶
Inferred node contexts to their mapped results.
Currently the key is
(node, lookupname, callcontext, boundnode)and the value is tuple of the inferred results
- lookupname: str | None¶
The original name of the node.
e.g. foo = 1 The inference of ‘foo’ is nodes.Const(1) but the lookup name is ‘foo’
- max_inferred = 100¶
- property nodes_inferred: int¶
Number of nodes inferred in this context and all its clones/descendents.
Wrap inner value in a mutable cell to allow for mutating a class variable in the presence of __slots__
- path¶
Path of visited nodes and their lookupname.
Currently this key is
(node, context.lookupname)
- push(node: nodes.NodeNG) bool[source]¶
Push node into inference path.
Allows one to see if the given node has already been looked at for this inference context