class documentation

class InferenceContext: (source)

View In Hierarchy

Provide context for inference.

Store already inferred nodes to save time. Account for already visited nodes to stop infinite recursion.

Method __init__ Do not instiate me directly, use copy_context() or Parser._new_context().
Method __str__ Undocumented
Method clone Clone inference path
Method nodes_inferred.setter Undocumented
Method push Push node into inference path
Class Variable __slots__ Undocumented
Class Variable max_inferred Undocumented
Instance Variable path type: set(NodeNG)
Property inferred Inferred (cached) nodes to their mapped results.
Property nodes_inferred Number of nodes inferred in this context and all its clones/descendents
Instance Variable _cache Store cache here instead of using a global variable.
Instance Variable _nodes_inferred Undocumented
def __init__(self, cache, path=None, nodes_inferred=None): (source)

Do not instiate me directly, use copy_context() or Parser._new_context().

Parameters
cache:_InferenceCacheUndocumented
path:Optional[List[ASTNodeT]]Undocumented
nodes_inferred:Optional[List[int]]Undocumented
def __str__(self): (source)

Undocumented

Returns
strUndocumented
def clone(self): (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

Returns
InferenceContextUndocumented
Note
If a new cache is needed for this context, use copy_context with argument: cache={}.
@nodes_inferred.setter
def nodes_inferred(self, value): (source)

Undocumented

Parameters
value:intUndocumented
def push(self, node): (source)

Push node into inference path

Allows one to see if the given node has already been looked at for this inference context

Parameters
node:ASTNodeTUndocumented
Returns
boolTrue if node is already in context path else False
__slots__: tuple[str, ...] = (source)

Undocumented

max_inferred: int = (source)

Undocumented

path = (source)

type: set(NodeNG)

List of visited nodes.

Inferred (cached) nodes to their mapped results.

@property
nodes_inferred: int = (source)

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__

Store cache here instead of using a global variable.

This dict is shared by all InferenceContext instances created by the method parser.Parser._new_context.

Two different parser.Parser instances will use two different caches.

More on the cache: https://github.com/PyCQA/astroid/pull/1009

_nodes_inferred: list[int] = (source)

Undocumented