This module contains a set of functions to handle inference on astroid trees.
Function | infer |
Undocumented |
Function | infer |
Infer a AssignName/AssignAttr: need to inspect the RHS part of the assign node. |
Function | infer |
Infer an Attribute node by using getattr on the associated object. |
Function | infer |
Undocumented |
Function | infer |
Undocumented |
Function | infer |
Infer a Call node by trying to guess what the function returns. |
Function | infer |
Undocumented |
Function | infer |
Inference's end for nodes that yield themselves on inference. |
Function | infer |
Undocumented |
Function | infer |
Undocumented |
Function | infer |
Support IfExp inference. |
Function | infer |
Infer an Import node: return the imported module/object. |
Function | infer |
Infer a ImportFrom node: return the imported module/object. |
Function | infer |
Undocumented |
Function | infer |
Infer a Name: use name lookup rules. |
Function | infer |
Undocumented |
Function | infer |
Inference for subscripts. |
Function | infer |
Infer what an UnaryOp should return when evaluated. |
Constant | COMPARE |
Undocumented |
Constant | UNINFERABLE |
Undocumented |
Type Alias |
|
Undocumented |
Variable | objects |
Undocumented |
Function | _aug |
Get an inference callable for an augmented binary operation. |
Function | _bin |
Get an inference callable for a normal binary operation. |
Function | _bin |
Create a new UnionType instance for binary or, e.g. int | str. |
Function | _do |
If all possible combinations are either True or False, return that: >>> _do_compare([1, 2], '<=', [3, 4]) True >>> _do_compare([1, 2], '==', [3, 4]) False |
Function | _filter |
Undocumented |
Function | _get |
Get the flow for augmented binary operations. |
Function | _get |
Get contexts for binary operations. |
Function | _get |
Get the flow for binary operations. |
Function | _higher |
Search for the first function which encloses the given scope. This can be used for looking up in that function's scope, in case looking up in a lower scope for a particular name fails. |
Function | _infer |
Inference logic for augmented binary operations. |
Function | _infer |
Infer a binary operation between a left operand and a right operand. |
Function | _infer |
Binary operation inference logic. |
Function | _infer |
Infer a boolean operation (and / or / not). |
Function | _infer |
Chained comparison inference logic. |
Function | _infer |
Infer all values based on Dict.items. |
Function | _infer |
Infer the result of '"string" % ...'. |
Function | _infer |
Infer all values based on _BaseContainer.elts. |
Function | _infer |
Infer what an UnaryOp should return when evaluated. |
Function | _invoke |
Invoke binary operation inference on the given instance. |
Function | _is |
Check if the given const node is NotImplemented. |
Function | _populate |
Undocumented |
Function | _same |
Check if type1 is the same as type2. |
Function | _to |
Undocumented |
Function | _update |
Delete nodes that equate to duplicate keys. |
Constant | _SUBSCRIPT |
Undocumented |
Type Variable | _ |
Undocumented |
Type Variable | _ |
Undocumented |
Type Variable | _T |
Undocumented |
def infer_arguments(self:
nodes.Arguments
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Undocumented
@decorators.path_wrapper
def infer_assign(self:
nodes.AssignName|nodes.AssignAttr
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Infer a AssignName/AssignAttr: need to inspect the RHS part of the assign node.
nodes.Attribute|nodes.AssignAttr
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, InferenceErrorInfo]
:
(source)
¶
Infer an Attribute node by using getattr on the associated object.
@decorators.path_wrapper
def infer_augassign(self:
nodes.AugAssign
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Undocumented
@decorators.path_wrapper
def infer_binop(self:
nodes.BinOp
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Undocumented
@decorators.path_wrapper
def infer_call(self:
nodes.Call
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, InferenceErrorInfo]
:
(source)
¶
Infer a Call node by trying to guess what the function returns.
@decorators.path_wrapper
def infer_empty_node(self:
nodes.EmptyNode
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Undocumented
_T
, context: InferenceContext|None
= None, **kwargs: Any
) -> Iterator[ _T]
:
(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 Consts.
_FunctionDefT
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ Property|_FunctionDefT, None, InferenceErrorInfo]
:
(source)
¶
Undocumented
@decorators.path_wrapper
def infer_global(self:
nodes.Global
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Undocumented
def infer_ifexp(self:
nodes.IfExp
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, 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.
@decorators.path_wrapper
def infer_import(self:
nodes.Import
, context: InferenceContext|None
= None, asname: bool
= True, **kwargs: Any
) -> Generator[ nodes.Module, None, None]
:
(source)
¶
Infer an Import node: return the imported module/object.
@decorators.path_wrapper
def infer_import_from(self:
nodes.ImportFrom
, context: InferenceContext|None
= None, asname: bool
= True, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Infer a ImportFrom node: return the imported module/object.
nodes.Dict
, context: InferenceContext|None
= None) -> Iterator[ nodes.Dict]
:
(source)
¶
Undocumented
nodes.Name|nodes.AssignName
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Infer a Name: use name lookup rules.
def infer_sequence(self:
_BaseContainerT
, context: InferenceContext|None
= None, **kwargs: Any
) -> Iterator[ _BaseContainerT]
:
(source)
¶
Undocumented
nodes.Subscript
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, InferenceErrorInfo|None]
:
(source)
¶
Inference for subscripts. We're understanding if the index is a Const or a slice, passing the result of inference to the value's `getitem` method, which should handle each supported index type accordingly.
@decorators.path_wrapper
def infer_unaryop(self:
nodes.UnaryOp
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, InferenceErrorInfo]
:
(source)
¶
Infer what an UnaryOp should return when evaluated.
Undocumented
Value |
|
Undocumented
Value |
|
InferenceResult
, opnode: nodes.AugAssign
, op: str
, other: InferenceResult
, context: InferenceContext
, reverse: bool
= False) -> functools.partial[ Generator[ InferenceResult, None, None]]
:
(source)
¶
Get an inference callable for an augmented binary operation.
InferenceResult
, opnode: nodes.AugAssign|nodes.BinOp
, op: str
, other: InferenceResult
, context: InferenceContext
, reverse: bool
= False) -> functools.partial[ Generator[ InferenceResult, None, None]]
:
(source)
¶
Get an inference callable for a normal binary operation. If *reverse* is True, then the reflected method will be used instead.
(bases.UnionType|nodes.ClassDef)|nodes.Const
, right: (bases.UnionType|nodes.ClassDef)|nodes.Const
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Create a new UnionType instance for binary or, e.g. int | str.
Iterable[ nodes.NodeNG]
, op: str
, right_iter: Iterable[ nodes.NodeNG]
) -> bool|util.UninferableBase
:
(source)
¶
If all possible combinations are either True or False, return that: >>> _do_compare([1, 2], '<=', [3, 4]) True >>> _do_compare([1, 2], '==', [3, 4]) False If any item is uninferable, or if some combinations are True and some are False, return Uninferable: >>> _do_compare([1, 3], '<=', [2, 4]) util.Uninferable
_T
, infer_callable: Callable[ [ _T, InferenceContext|None], Generator[ InferenceResult|util.BadOperationMessage, None, None]]
, context: InferenceContext|None
, error: type[ util.BadOperationMessage]
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Undocumented
InferenceResult
, left_type: InferenceResult|None
, aug_opnode: nodes.AugAssign
, right: InferenceResult
, right_type: InferenceResult|None
, context: InferenceContext
, reverse_context: InferenceContext
) -> list[ functools.partial[ Generator[ InferenceResult, None, None]]]
:
(source)
¶
Get the flow for augmented binary operations. The rules are a bit messy: * if left and right have the same type, then left.__augop__(right) is first tried and then left.__op__(right). * if left and right are unrelated typewise, then left.__augop__(right) is tried, then left.__op__(right) is tried and then right.__rop__(left) is tried. * if left is a subtype of right, then left.__augop__(right) is tried and then left.__op__(right). * if left is a supertype of right, then left.__augop__(right) is tried, then right.__rop__(left) and then left.__op__(right)
Get contexts for binary operations. This will return two inference contexts, the first one for x.__op__(y), the other one for y.__rop__(x), where only the arguments are inversed.
InferenceResult
, left_type: InferenceResult|None
, binary_opnode: nodes.AugAssign|nodes.BinOp
, right: InferenceResult
, right_type: InferenceResult|None
, context: InferenceContext
, reverse_context: InferenceContext
) -> list[ functools.partial[ Generator[ InferenceResult, None, None]]]
:
(source)
¶
Get the flow for binary operations. The rules are a bit messy: * if left and right have the same type, then only one method will be called, left.__op__(right) * if left and right are unrelated typewise, then first left.__op__(right) is tried and if this does not exist or returns NotImplemented, then right.__rop__(left) is tried. * if left is a subtype of right, then only left.__op__(right) is tried. * if left is a supertype of right, then right.__rop__(left) is first tried and then left.__op__(right)
Search for the first function which encloses the given scope. This can be used for looking up in that function's scope, in case looking up in a lower scope for a particular name fails. :param node: A scope node. :returns: ``None``, if no parent function scope was found, otherwise an instance of :class:`astroid.nodes.scoped_nodes.Function`, which encloses the given node.
nodes.AugAssign
, context: InferenceContext|None
= None) -> Generator[ InferenceResult|util.BadBinaryOperationMessage, None, None]
:
(source)
¶
Inference logic for augmented binary operations.
InferenceResult
, right: InferenceResult
, binary_opnode: nodes.AugAssign|nodes.BinOp
, context: InferenceContext
, flow_factory: GetFlowFactory
) -> Generator[ InferenceResult|util.BadBinaryOperationMessage, None, None]
:
(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, the only difference is the flow factory used.
nodes.BinOp
, context: InferenceContext|None
= None) -> Generator[ InferenceResult|util.BadBinaryOperationMessage, None, None]
:
(source)
¶
Binary operation inference logic.
@decorators.path_wrapper
def _infer_boolop(self:
nodes.BoolOp
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, InferenceErrorInfo|None]
:
(source)
¶
Infer a boolean operation (and / or / not). The function will calculate the boolean operation for all pairs generated through inference for each component node.
nodes.Compare
, context: InferenceContext|None
= None, **kwargs: Any
) -> Generator[ nodes.Const|util.UninferableBase, None, None]
:
(source)
¶
Chained comparison inference logic.
nodes.Dict
, context: InferenceContext|None
) -> dict[ SuccessfulInferenceResult, SuccessfulInferenceResult]
:
(source)
¶
Infer all values based on Dict.items.
nodes.Const
, other: nodes.NodeNG
, context: InferenceContext
) -> tuple[ util.UninferableBase|nodes.Const]
:
(source)
¶
Infer the result of '"string" % ...'. TODO: Instead of returning Uninferable we should rely on the call to '%' to see if the result is actually uninferable.
_BaseContainerT
, context: InferenceContext|None
= None) -> list[ SuccessfulInferenceResult]
:
(source)
¶
Infer all values based on _BaseContainer.elts.
nodes.UnaryOp
, context: InferenceContext|None
= None) -> Generator[ InferenceResult|util.BadUnaryOperationMessage, None, None]
:
(source)
¶
Infer what an UnaryOp should return when evaluated.
InferenceResult
, opnode: nodes.AugAssign|nodes.BinOp
, op: str
, other: InferenceResult
, context: InferenceContext
, method_name: str
) -> Generator[ InferenceResult, None, None]
:
(source)
¶
Invoke binary operation inference on the given instance.
dict[ SuccessfulInferenceResult, SuccessfulInferenceResult]
, rhs_dict: dict[ SuccessfulInferenceResult, SuccessfulInferenceResult]
) -> dict[ SuccessfulInferenceResult, SuccessfulInferenceResult]
:
(source)
¶
Delete nodes that equate to duplicate keys. Since an astroid node doesn't 'equal' another node with the same value, this function uses the as_string method to make sure duplicate keys don't get through Note that both the key and the value are astroid nodes Fixes issue with DictUnpack causing duplicate keys in inferred Dict items :param lhs_dict: Dictionary to 'merge' nodes into :param rhs_dict: Dictionary with nodes to pull from :return : merged dictionary of nodes