module documentation

Core of the inference engine.

Function get_attr Get local attributes definitions matching the name from this frame node.
Function get_submodule Undocumented
Function infer Get a generator of the inferred values. See ASTNode.infer.
Function infer_attr Infer the possible values of the given variable.
Function safe_infer Return the inferred value for the given node.
Function _get_end_of_frame_sentinel Undocumented
Function _get_infer_meth Undocumented
Function _infer Redirects to the right method to infer a node. Equivalent to ast astroid's NodeNG._infer() method.
Function _infer_alias Undocumented
Function _infer_assign_name From astroid's inference.infer_assign() function.
Function _infer_Attribute Undocumented
Function _infer_AugAssign Inference logic for augmented binary operations.
Function _infer_BinOp Binary operation inference logic.
Function _infer_end Inference's end for nodes that yield themselves on inference
Function _infer_IfExp Support IfExp inference
Function _infer_Index Undocumented
Function _infer_lhs Infers the left hand side in augmented binary operations.
Function _infer_name Infer a Name: use name lookup rules.
Function _infer_Name Undocumented
Function _infer_sequence Undocumented
Function _infer_sequence_helper Infer all values based on elts.
Function _infer_stmts Return an iterator on statements inferred by each statement in stmts.
Function _invoke_binop_inference Infer a binary operation between a left operand and a right operand.
Function _is_end_of_frame_sentinel Undocumented
Function _raise_no_infer_method we don't know how to resolve a statement by default
Constant _AUGMENTED_OPERATORS Undocumented
Constant _OPPERATORS Undocumented
Variable _globals Undocumented
def get_attr(ctx, name, *, ignore_locals=False, context=None): (source)

Get local attributes definitions matching the name from this frame node.

Parameters
ctx:_typing.FrameNodeTUndocumented
name:strUndocumented
ignore_locals:boolUndocumented
context:OptionalInferenceContextUndocumented
Returns
List[ASTNodeT]Undocumented
def get_submodule(pack, name, *, context=None): (source)

Undocumented

Parameters
pack:_typing.ModuleUndocumented
name:strUndocumented
context:OptionalInferenceContextUndocumented
Returns
Optional[ASTNodeT]Undocumented
def infer(self, context=None): (source)

Get a generator of the inferred values. See ASTNode.infer.

This is kinda the main entry point to the inference system.

Parameters
context:OptionalInferenceContextUndocumented
Returns
iterableThe inferred values.
def infer_attr(ctx, name, *, context=None): (source)

Infer the possible values of the given variable.

Parameters
ctx:ASTNodeTUndocumented
name:strThe name of the variable to infer.
context:OptionalInferenceContextUndocumented
Returns
InferResultThe inferred possible values.
def safe_infer(node, context=None): (source)

Return the inferred value for the given node.

Return None if inference failed, it's Uninfereable or if there is some ambiguity (more than one node has been inferred).

Parameters
node:ASTNodeTUndocumented
context:OptionalInferenceContextUndocumented
Returns
Optional[ASTNodeT]Undocumented
def _get_end_of_frame_sentinel(frame_node): (source)

Undocumented

Parameters
frame_node:_typing.FrameNodeTUndocumented
Returns
_typing.ASTstmtUndocumented
@functools.lru_cache()
def _get_infer_meth(node): (source)

Undocumented

Parameters
node:ASTNodeTUndocumented
Returns
_InferMethTUndocumented
def _infer(node, context): (source)

Redirects to the right method to infer a node. Equivalent to ast astroid's NodeNG._infer() method.

Parameters
node:ASTNodeTUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@raise_if_nothing_inferred
@path_wrapper
def _infer_alias(self, context=None): (source)

Undocumented

Parameters
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
def _infer_assign_name(node, context): (source)

From astroid's inference.infer_assign() function.

Parameters
node:ASTNodeTUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@path_wrapper
@raise_if_nothing_inferred
def _infer_Attribute(node, context): (source)

Undocumented

Parameters
node:_typing.AttributeUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@raise_if_nothing_inferred
@path_wrapper
def _infer_AugAssign(self, context=None): (source)

Inference logic for augmented binary operations.

Parameters
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@yes_if_nothing_inferred
@path_wrapper
def _infer_BinOp(self, context): (source)

Binary operation inference logic.

Parameters
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
Note
From astroid's inference._infer_binop() function.
def _infer_end(node, context): (source)

Inference's end for nodes that yield themselves on inference

These are objects for which inference does not have any semantic, such as Module or Constants.

Parameters
node:ASTNodeTUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@raise_if_nothing_inferred
def _infer_IfExp(node, context=None): (source)

Support IfExp inference

If we can't infer the truthiness of the condition, we default to inferring both branches. Otherwise, we infer either branch depending on the condition.

Parameters
node:_typing.IfExpUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@raise_if_nothing_inferred
def _infer_Index(self, context=None): (source)

Undocumented

Parameters
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
def _infer_lhs(node, context): (source)

Infers the left hand side in augmented binary operations.

@note: It only supports ast.Name instances at the moment.

Parameters
node:ast.exprUndocumented
context:InferenceContextUndocumented
Returns
InferResultUndocumented
def _infer_name(self, context=None): (source)

Infer a Name: use name lookup rules.

Parameters
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@path_wrapper
@raise_if_nothing_inferred
def _infer_Name(node, context): (source)

Undocumented

Parameters
node:_typing.NameUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
@raise_if_nothing_inferred
def _infer_sequence(self, context=None, assign_context=False): (source)

Undocumented

Parameters
context:OptionalInferenceContextUndocumented
assign_context:boolUndocumented
Returns
InferResultUndocumented
def _infer_sequence_helper(node, context=None, infer_all_elements=True): (source)

Infer all values based on elts.

If infer_all_elements is False, will only infer Starred and NamedExpr inside the list, this is used for tuple assignments.

Parameters
node:Union[_typing.Tuple, _typing.List, _typing.Set]Undocumented
context:OptionalInferenceContextUndocumented
infer_all_elements:boolUndocumented
Returns
List[ASTNodeT]Undocumented
def _infer_stmts(stmts, context, frame=None): (source)

Return an iterator on statements inferred by each statement in stmts.

Parameters
stmts:List[Union[ASTNodeT, UninferableT]]Undocumented
context:InferenceContextUndocumented
frame:Optional[ASTNodeT]Undocumented
Returns
InferResultUndocumented
def _invoke_binop_inference(left, opnode, op, right, context): (source)

Infer a binary operation between a left operand and a right operand.

This is used by both normal binary operations and augmented binary operations.

Parameters
left:ASTNodeTUndocumented
opnode:Union[_typing.BinOp, _typing.AugAssign]Undocumented
op:ast.operatorUndocumented
right:ASTNodeTUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
Note
left and right are inferred nodes.
def _is_end_of_frame_sentinel(node): (source)

Undocumented

Parameters
node:_typing.ASTNodeUndocumented
Returns
boolUndocumented
def _raise_no_infer_method(node, context): (source)

we don't know how to resolve a statement by default

Parameters
node:ASTNodeTUndocumented
context:OptionalInferenceContextUndocumented
Returns
InferResultUndocumented
_AUGMENTED_OPERATORS = (source)

Undocumented

Value
{ast.Add: (lambda a, b: operatorlib.iadd(a, b)),
 ast.Sub: (lambda a, b: operatorlib.isub(a, b)),
 ast.Mult: (lambda a, b: operatorlib.imul(a, b)),
 ast.Div: (lambda a, b: operatorlib.itruediv(a, b)),
 ast.FloorDiv: (lambda a, b: operatorlib.ifloordiv(a, b)),
 ast.Mod: (lambda a, b: operatorlib.imod(a, b)),
 ast.Pow: (lambda a, b: operatorlib.ipow(a, b)),
...
_OPPERATORS = (source)

Undocumented

Value
{ast.Not: (lambda o: not o),
 ast.Invert: (lambda o: ~o),
 ast.UAdd: (lambda o: +o),
 ast.USub: (lambda o: -o),
 ast.Add: (lambda a, b: a + b),
 ast.Sub: (lambda a, b: a - b),
 ast.Mult: (lambda a, b: a * b),
...
_globals = (source)

Undocumented