Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and jacobtylerwalls committed Aug 4, 2024
1 parent 4122248 commit 92baf78
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 49 deletions.
16 changes: 6 additions & 10 deletions astroid/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ def wrapped(


def yes_if_nothing_inferred(
func: Callable[_P, Generator[InferenceResult, None, None]]
) -> Callable[_P, Generator[InferenceResult, None, None]]:
def inner(
*args: _P.args, **kwargs: _P.kwargs
) -> Generator[InferenceResult, None, None]:
func: Callable[_P, Generator[InferenceResult]]
) -> Callable[_P, Generator[InferenceResult]]:
def inner(*args: _P.args, **kwargs: _P.kwargs) -> Generator[InferenceResult]:
generator = func(*args, **kwargs)

try:
Expand All @@ -80,11 +78,9 @@ def inner(


def raise_if_nothing_inferred(
func: Callable[_P, Generator[InferenceResult, None, None]],
) -> Callable[_P, Generator[InferenceResult, None, None]]:
def inner(
*args: _P.args, **kwargs: _P.kwargs
) -> Generator[InferenceResult, None, None]:
func: Callable[_P, Generator[InferenceResult]],
) -> Callable[_P, Generator[InferenceResult]]:
def inner(*args: _P.args, **kwargs: _P.kwargs) -> Generator[InferenceResult]:
generator = func(*args, **kwargs)
try:
yield next(generator)
Expand Down
2 changes: 1 addition & 1 deletion astroid/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _function_type(

def _object_type(
node: InferenceResult, context: InferenceContext | None = None
) -> Generator[InferenceResult | None, None, None]:
) -> Generator[InferenceResult | None]:
astroid_manager = manager.AstroidManager()
builtins = astroid_manager.builtins_module
context = context or InferenceContext()
Expand Down
2 changes: 1 addition & 1 deletion astroid/inference_tip.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def inner(
node: _NodesT,
context: InferenceContext | None = None,
**kwargs: Any,
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
partial_cache_key = (func, node)
if partial_cache_key in _CURRENTLY_INFERRING:
# If through recursion we end up trying to infer the same
Expand Down
18 changes: 9 additions & 9 deletions astroid/nodes/_base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ class OperatorNode(NodeNG):
def _filter_operation_errors(
infer_callable: Callable[
[InferenceContext | None],
Generator[InferenceResult | util.BadOperationMessage, None, None],
Generator[InferenceResult | util.BadOperationMessage],
],
context: InferenceContext | None,
error: type[util.BadOperationMessage],
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
for result in infer_callable(context):
if isinstance(result, error):
# For the sake of .infer(), we don't care about operation
Expand Down Expand Up @@ -392,7 +392,7 @@ def _invoke_binop_inference(
other: InferenceResult,
context: InferenceContext,
method_name: str,
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
"""Invoke binary operation inference on the given instance."""
methods = dunder_lookup.lookup(instance, method_name)
context = bind_context_to_node(context, instance)
Expand Down Expand Up @@ -431,7 +431,7 @@ def _aug_op(
other: InferenceResult,
context: InferenceContext,
reverse: bool = False,
) -> partial[Generator[InferenceResult, None, None]]:
) -> partial[Generator[InferenceResult]]:
"""Get an inference callable for an augmented binary operation."""
method_name = AUGMENTED_OP_METHOD[op]
return partial(
Expand All @@ -452,7 +452,7 @@ def _bin_op(
other: InferenceResult,
context: InferenceContext,
reverse: bool = False,
) -> partial[Generator[InferenceResult, None, None]]:
) -> partial[Generator[InferenceResult]]:
"""Get an inference callable for a normal binary operation.
If *reverse* is True, then the reflected method will be used instead.
Expand All @@ -475,7 +475,7 @@ def _bin_op(
def _bin_op_or_union_type(
left: bases.UnionType | nodes.ClassDef | nodes.Const,
right: bases.UnionType | nodes.ClassDef | nodes.Const,
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
"""Create a new UnionType instance for binary or, e.g. int | str."""
yield bases.UnionType(left, right)

Expand Down Expand Up @@ -509,7 +509,7 @@ def _get_aug_flow(
right_type: InferenceResult | None,
context: InferenceContext,
reverse_context: InferenceContext,
) -> list[partial[Generator[InferenceResult, None, None]]]:
) -> list[partial[Generator[InferenceResult]]]:
"""Get the flow for augmented binary operations.
The rules are a bit messy:
Expand Down Expand Up @@ -566,7 +566,7 @@ def _get_binop_flow(
right_type: InferenceResult | None,
context: InferenceContext,
reverse_context: InferenceContext,
) -> list[partial[Generator[InferenceResult, None, None]]]:
) -> list[partial[Generator[InferenceResult]]]:
"""Get the flow for binary operations.
The rules are a bit messy:
Expand Down Expand Up @@ -627,7 +627,7 @@ def _infer_binary_operation(
binary_opnode: nodes.AugAssign | nodes.BinOp,
context: InferenceContext,
flow_factory: GetFlowFactory,
) -> Generator[InferenceResult | util.BadBinaryOperationMessage, None, None]:
) -> Generator[InferenceResult | util.BadBinaryOperationMessage]:
"""Infer a binary operation between a left operand and a right operand.
This is used by both normal binary operations and augmented binary
Expand Down
26 changes: 13 additions & 13 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ def get_children(self):
@decorators.raise_if_nothing_inferred
def _infer(
self: nodes.Arguments, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
# pylint: disable-next=import-outside-toplevel
from astroid.protocols import _arguments_infer_argname

Expand Down Expand Up @@ -1417,7 +1417,7 @@ def _get_yield_nodes_skip_lambdas(self):

def _infer_augassign(
self, context: InferenceContext | None = None
) -> Generator[InferenceResult | util.BadBinaryOperationMessage, None, None]:
) -> Generator[InferenceResult | util.BadBinaryOperationMessage]:
"""Inference logic for augmented binary operations."""
context = context or InferenceContext()

Expand Down Expand Up @@ -1447,7 +1447,7 @@ def _infer_augassign(
@decorators.path_wrapper
def _infer(
self: nodes.AugAssign, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
return self._filter_operation_errors(
self._infer_augassign, context, util.BadBinaryOperationMessage
)
Expand Down Expand Up @@ -1532,7 +1532,7 @@ def op_left_associative(self) -> bool:

def _infer_binop(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
"""Binary operation inference logic."""
left = self.left
right = self.right
Expand Down Expand Up @@ -1562,7 +1562,7 @@ def _infer_binop(
@decorators.path_wrapper
def _infer(
self: nodes.BinOp, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
return self._filter_operation_errors(
self._infer_binop, context, util.BadBinaryOperationMessage
)
Expand Down Expand Up @@ -1911,7 +1911,7 @@ def _do_compare(

def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[nodes.Const | util.UninferableBase, None, None]:
) -> Generator[nodes.Const | util.UninferableBase]:
"""Chained comparison inference logic."""
retval: bool | util.UninferableBase = True

Expand Down Expand Up @@ -2561,7 +2561,7 @@ def has_underlying_object(self) -> bool:
@decorators.path_wrapper
def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
if not self.has_underlying_object():
yield util.Uninferable
else:
Expand Down Expand Up @@ -2851,7 +2851,7 @@ def _infer(
context: InferenceContext | None = None,
asname: bool = True,
**kwargs: Any,
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
"""Infer a ImportFrom node: return the imported module/object."""
context = context or InferenceContext()
name = context.lookupname
Expand Down Expand Up @@ -2976,7 +2976,7 @@ def _infer_name(self, frame, name):
@decorators.path_wrapper
def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
if context is None or context.lookupname is None:
raise InferenceError(node=self, context=context)
try:
Expand Down Expand Up @@ -3093,7 +3093,7 @@ def op_left_associative(self) -> Literal[False]:
@decorators.raise_if_nothing_inferred
def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
"""Support IfExp inference.
If we can't infer the truthiness of the condition, we default
Expand Down Expand Up @@ -3182,7 +3182,7 @@ def _infer(
context: InferenceContext | None = None,
asname: bool = True,
**kwargs: Any,
) -> Generator[nodes.Module, None, None]:
) -> Generator[nodes.Module]:
"""Infer an Import node: return the imported module/object."""
context = context or InferenceContext()
name = context.lookupname
Expand Down Expand Up @@ -4123,7 +4123,7 @@ def _infer(
InferenceContext | None,
None,
],
Generator[NodeNG, None, None],
Generator[NodeNG],
]
] = protocols.assign_assigned_stmts

Expand Down Expand Up @@ -4984,7 +4984,7 @@ def __init__(

def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[NodeNG | util.UninferableBase, None, None]:
) -> Generator[NodeNG | util.UninferableBase]:
yield self.value


Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/node_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(

def infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
"""Get a generator of the inferred values.
This is the main entry point to the inference system.
Expand Down
8 changes: 4 additions & 4 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def frame(self: _T, *, future: Literal[None, True] = None) -> _T:

def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[Module, None, None]:
) -> Generator[Module]:
yield self


Expand Down Expand Up @@ -1052,7 +1052,7 @@ def getattr(

def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[Lambda, None, None]:
) -> Generator[Lambda]:
yield self

def _get_yield_nodes_skip_functions(self):
Expand Down Expand Up @@ -2222,7 +2222,7 @@ def basenames(self):

def ancestors(
self, recurs: bool = True, context: InferenceContext | None = None
) -> Generator[ClassDef, None, None]:
) -> Generator[ClassDef]:
"""Iterate over the base classes in prefixed depth first order.
:param recurs: Whether to recurse or return direct ancestors only.
Expand Down Expand Up @@ -2975,5 +2975,5 @@ def frame(self: _T, *, future: Literal[None, True] = None) -> _T:

def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[ClassDef, None, None]:
) -> Generator[ClassDef]:
yield self
2 changes: 1 addition & 1 deletion astroid/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,5 @@ def infer_call_result(

def _infer(
self: _T, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[_T, None, None]:
) -> Generator[_T]:
yield self
16 changes: 8 additions & 8 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def const_infer_binary_op(
other: InferenceResult,
context: InferenceContext,
_: SuccessfulInferenceResult,
) -> Generator[ConstFactoryResult | util.UninferableBase, None, None]:
) -> Generator[ConstFactoryResult | util.UninferableBase]:
not_implemented = nodes.Const(NotImplemented)
if isinstance(other, nodes.Const):
if (
Expand Down Expand Up @@ -176,7 +176,7 @@ def tl_infer_binary_op(
other: InferenceResult,
context: InferenceContext,
method: SuccessfulInferenceResult,
) -> Generator[_TupleListNodeT | nodes.Const | util.UninferableBase, None, None]:
) -> Generator[_TupleListNodeT | nodes.Const | util.UninferableBase]:
"""Infer a binary operation on a tuple or list.
The instance on which the binary operation is performed is a tuple
Expand Down Expand Up @@ -224,7 +224,7 @@ def instance_class_infer_binary_op(
other: InferenceResult,
context: InferenceContext,
method: SuccessfulInferenceResult,
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
return method.infer_call_result(self, context)


Expand Down Expand Up @@ -347,7 +347,7 @@ def assend_assigned_stmts(

def _arguments_infer_argname(
self, name: str | None, context: InferenceContext
) -> Generator[InferenceResult, None, None]:
) -> Generator[InferenceResult]:
# arguments information may be missing, in which case we can't do anything
# more
from astroid import arguments # pylint: disable=import-outside-toplevel
Expand Down Expand Up @@ -877,7 +877,7 @@ def match_mapping_assigned_stmts(
node: nodes.AssignName,
context: InferenceContext | None = None,
assign_path: None = None,
) -> Generator[nodes.NodeNG, None, None]:
) -> Generator[nodes.NodeNG]:
"""Return empty generator (return -> raises StopIteration) so inferred value
is Uninferable.
"""
Expand All @@ -891,7 +891,7 @@ def match_star_assigned_stmts(
node: nodes.AssignName,
context: InferenceContext | None = None,
assign_path: None = None,
) -> Generator[nodes.NodeNG, None, None]:
) -> Generator[nodes.NodeNG]:
"""Return empty generator (return -> raises StopIteration) so inferred value
is Uninferable.
"""
Expand All @@ -905,7 +905,7 @@ def match_as_assigned_stmts(
node: nodes.AssignName,
context: InferenceContext | None = None,
assign_path: None = None,
) -> Generator[nodes.NodeNG, None, None]:
) -> Generator[nodes.NodeNG]:
"""Infer MatchAs as the Match subject if it's the only MatchCase pattern
else raise StopIteration to yield Uninferable.
"""
Expand All @@ -923,7 +923,7 @@ def generic_type_assigned_stmts(
node: nodes.AssignName,
context: InferenceContext | None = None,
assign_path: None = None,
) -> Generator[nodes.NodeNG, None, None]:
) -> Generator[nodes.NodeNG]:
"""Hack. Return any Node so inference doesn't fail
when evaluating __class_getitem__. Revert if it's causing issues.
"""
Expand Down
2 changes: 1 addition & 1 deletion astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def visit_delete(self, node: ast.Delete, parent: NodeNG) -> nodes.Delete:

def _visit_dict_items(
self, node: ast.Dict, parent: NodeNG, newnode: nodes.Dict
) -> Generator[tuple[NodeNG, NodeNG], None, None]:
) -> Generator[tuple[NodeNG, NodeNG]]:
for key, value in zip(node.keys, node.values):
rebuilt_key: NodeNG
rebuilt_value = self.visit(value, newnode)
Expand Down

0 comments on commit 92baf78

Please sign in to comment.