module documentation

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 self: nodes.Starred node: a node related to the current underlying Node. context: Inference context used for caching already inferred objects assign_path:
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: nodes.Arguments, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

def assend_assigned_stmts(self: nodes.AssignName | nodes.AssignAttr, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

def assign_annassigned_stmts(self: nodes.AnnAssign, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

@decorators.raise_if_nothing_inferred
def assign_assigned_stmts(self: nodes.AugAssign | nodes.Assign | nodes.AnnAssign, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

@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: nodes.ExceptHandler, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

@decorators.raise_if_nothing_inferred
def for_assigned_stmts(self: nodes.For | nodes.Comprehension, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

@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: nodes.MatchAs, node: nodes.AssignName, context: InferenceContext | None = None, assign_path: Literal[None] = None) -> Generator[nodes.NodeNG, None, None]: (source)

Infer MatchAs as the Match subject if it's the only MatchCase pattern else raise StopIteration to yield Uninferable.

@decorators.yes_if_nothing_inferred
def match_mapping_assigned_stmts(self: nodes.MatchMapping, node: nodes.AssignName, context: InferenceContext | None = None, assign_path: Literal[None] = None) -> Generator[nodes.NodeNG, None, None]: (source)

Return empty generator (return -> raises StopIteration) so inferred value is Uninferable.

@decorators.yes_if_nothing_inferred
def match_star_assigned_stmts(self: nodes.MatchStar, node: nodes.AssignName, context: InferenceContext | None = None, assign_path: Literal[None] = None) -> Generator[nodes.NodeNG, None, None]: (source)

Return empty generator (return -> raises StopIteration) so inferred value is Uninferable.

@decorators.raise_if_nothing_inferred
def named_expr_assigned_stmts(self: nodes.NamedExpr, node: node_classes.AssignedStmtsPossibleNode, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Infer names and other nodes from an assignment expression

def sequence_assigned_stmts(self: nodes.Tuple | nodes.List, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (source)

Undocumented

@decorators.yes_if_nothing_inferred
def starred_assigned_stmts(self: nodes.Starred, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (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.

@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: nodes.With, node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) -> Any: (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.
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}

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_}