module documentation
(source)

this module contains a set of functions to handle python protocols for nodes where it makes sense.
Function arguments​_assigned​_stmts Undocumented
Function assend​_assigned​_stmts Undocumented
Function assign​_annassigned​_stmts Undocumented
Function assign​_assigned​_stmts Undocumented
Function const​_infer​_binary​_op Undocumented
Function excepthandler​_assigned​_stmts Undocumented
Function for​_assigned​_stmts Undocumented
Function instance​_class​_infer​_binary​_op Undocumented
Function match​_as​_assigned​_stmts Infer MatchAs as the Match subject if it's the only MatchCase pattern else raise StopIteration to yield Uninferable.
Function match​_mapping​_assigned​_stmts Return empty generator (return -> raises StopIteration) so inferred value is Uninferable.
Function match​_star​_assigned​_stmts Return empty generator (return -> raises StopIteration) so inferred value is Uninferable.
Function named​_expr​_assigned​_stmts Infer names and other nodes from an assignment expression
Function sequence​_assigned​_stmts Undocumented
Function starred​_assigned​_stmts No summary
Function tl​_infer​_binary​_op Undocumented
Function with​_assigned​_stmts Infer names and other nodes from a with statement.
Constant AUGMENTED​_OP​_METHOD Undocumented
Constant BIN​_OP​_IMPL Undocumented
Constant BIN​_OP​_METHOD Undocumented
Constant REFLECTED​_BIN​_OP​_METHOD Undocumented
Constant UNARY​_OP​_METHOD Undocumented
Variable objects Undocumented
Variable raw​_building Undocumented
Function _arguments​_infer​_argname Undocumented
Function _augmented​_name Undocumented
Function _filter​_uninferable​_nodes Undocumented
Function _infer​_context​_manager Undocumented
Function _infer​_unary​_op Undocumented
Function _multiply​_seq​_by​_int Undocumented
Function _reflected​_name Undocumented
Function _resolve​_assignment​_parts recursive function to resolve multiple assignments
Function _resolve​_looppart recursive function to resolve multiple assignments on loops
Constant _CONTEXTLIB​_MGR Undocumented
Constant _UNARY​_OPERATORS Undocumented
def arguments_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
def assend_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
def assign_annassigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
@decorators.raise_if_nothing_inferred
def assign_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
@decorators.yes_if_nothing_inferred
def const_infer_binary_op(self, opnode, operator, other, context, _): (source)

Undocumented

@decorators.raise_if_nothing_inferred
def excepthandler_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
@decorators.raise_if_nothing_inferred
def for_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
@decorators.yes_if_nothing_inferred
def instance_class_infer_binary_op(self, opnode, operator, other, context, method): (source)

Undocumented

@decorators.yes_if_nothing_inferred
def match_as_assigned_stmts(self, node, context=None, assign_path=None): (source)
Infer MatchAs as the Match subject if it's the only MatchCase pattern else raise StopIteration to yield Uninferable.
Parameters
node:nodes.AssignNameUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Literal[None]Undocumented
Returns
Generator[nodes.NodeNG, None, None]Undocumented
@decorators.yes_if_nothing_inferred
def match_mapping_assigned_stmts(self, node, context=None, assign_path=None): (source)
Return empty generator (return -> raises StopIteration) so inferred value is Uninferable.
Parameters
node:nodes.AssignNameUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Literal[None]Undocumented
Returns
Generator[nodes.NodeNG, None, None]Undocumented
@decorators.yes_if_nothing_inferred
def match_star_assigned_stmts(self, node, context=None, assign_path=None): (source)
Return empty generator (return -> raises StopIteration) so inferred value is Uninferable.
Parameters
node:nodes.AssignNameUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Literal[None]Undocumented
Returns
Generator[nodes.NodeNG, None, None]Undocumented
@decorators.raise_if_nothing_inferred
def named_expr_assigned_stmts(self, node, context=None, assign_path=None): (source)
Infer names and other nodes from an assignment expression
Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
def sequence_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Undocumented

Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
@decorators.yes_if_nothing_inferred
def starred_assigned_stmts(self, node=None, context=None, assign_path=None): (source)
Arguments:

self: nodes.Starred node: a node related to the current underlying Node. context: Inference context used for caching already inferred objects assign_path:

A list of indices, where each index specifies what item to fetch from the inference results.
Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
@decorators.yes_if_nothing_inferred
def tl_infer_binary_op(self, opnode, operator, other, context, method): (source)

Undocumented

@decorators.raise_if_nothing_inferred
def with_assigned_stmts(self, node=None, context=None, assign_path=None): (source)

Infer names and other nodes from a with statement.

This enables only inference for name binding in a with statement. For instance, in the following code, inferring func will return the ContextManager class, not whatever __enter__ returns. We are doing this intentionally, because we consider that the context manager result is whatever __enter__ returns and what it is binded using the as keyword.

class ContextManager(object):
def __enter__(self):
return 42
with ContextManager() as f:
pass

# ContextManager().infer() will return ContextManager # f.infer() will return 42.

Arguments:

self: nodes.With node: The target of the assignment, as (a, b) in with foo as (a, b). context: Inference context used for caching already inferred objects assign_path:

A list of indices, where each index specifies what item to fetch from the inference results.
Parameters
node:node_classes.AssignedStmtsPossibleNodeUndocumented
context:Optional[InferenceContext]Undocumented
assign​_path:Optional[List[int]]Undocumented
Returns
AnyUndocumented
AUGMENTED_OP_METHOD = (source)

Undocumented

Value
{(key + '='): _augmented_name(value) for key, value in BIN_OP_METHOD.items()}
BIN_OP_IMPL = (source)

Undocumented

Value
{'+': (lambda a, b: a + b),
 '-': (lambda a, b: a - b),
 '/': (lambda a, b: a / b),
 '//': (lambda a, b: a // b),
 '*': (lambda a, b: a * b),
 '**': (lambda a, b: a ** b),
 '%': (lambda a, b: a % b),
...
BIN_OP_METHOD: dict[str, str] = (source)

Undocumented

Value
{'+': '__add__',
 '-': '__sub__',
 '/': '__truediv__',
 '//': '__floordiv__',
 '*': '__mul__',
 '**': '__pow__',
 '%': '__mod__',
...
REFLECTED_BIN_OP_METHOD = (source)

Undocumented

Value
{key: _reflected_name(value) for key, value in BIN_OP_METHOD.items()}
UNARY_OP_METHOD: dict = (source)

Undocumented

Value
{'+': '__pos__', '-': '__neg__', '~': '__invert__', 'not': None}
objects = (source)

Undocumented

raw_building = (source)

Undocumented

def _arguments_infer_argname(self, name, context): (source)

Undocumented

def _augmented_name(name): (source)

Undocumented

def _filter_uninferable_nodes(elts, context): (source)

Undocumented

def _infer_context_manager(self, mgr, context): (source)

Undocumented

def _infer_unary_op(obj, op): (source)

Undocumented

def _multiply_seq_by_int(self, opnode, other, context): (source)

Undocumented

def _reflected_name(name): (source)

Undocumented

def _resolve_assignment_parts(parts, assign_path, context): (source)
recursive function to resolve multiple assignments
def _resolve_looppart(parts, assign_path, context): (source)
recursive function to resolve multiple assignments on loops
_CONTEXTLIB_MGR: str = (source)

Undocumented

Value
'contextlib.contextmanager'
_UNARY_OPERATORS = (source)

Undocumented

Value
{'+': operator_mod.pos,
 '-': operator_mod.neg,
 '~': operator_mod.invert,
 'not': operator_mod.not_}