From 92baf7833d667f69df05a33b860a6e8693e3ff1c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 22:48:57 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/decorators.py | 16 +++++-------- astroid/helpers.py | 2 +- astroid/inference_tip.py | 2 +- astroid/nodes/_base_nodes.py | 18 +++++++-------- astroid/nodes/node_classes.py | 26 +++++++++++----------- astroid/nodes/node_ng.py | 2 +- astroid/nodes/scoped_nodes/scoped_nodes.py | 8 +++---- astroid/objects.py | 2 +- astroid/protocols.py | 16 ++++++------- astroid/rebuilder.py | 2 +- 10 files changed, 45 insertions(+), 49 deletions(-) diff --git a/astroid/decorators.py b/astroid/decorators.py index 8baca60b67..6c8b1bac32 100644 --- a/astroid/decorators.py +++ b/astroid/decorators.py @@ -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: @@ -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) diff --git a/astroid/helpers.py b/astroid/helpers.py index 244612146f..fe57b16bbc 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -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() diff --git a/astroid/inference_tip.py b/astroid/inference_tip.py index cb1fb37909..c3187c0670 100644 --- a/astroid/inference_tip.py +++ b/astroid/inference_tip.py @@ -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 diff --git a/astroid/nodes/_base_nodes.py b/astroid/nodes/_base_nodes.py index d2bf331299..96c3c1c06d 100644 --- a/astroid/nodes/_base_nodes.py +++ b/astroid/nodes/_base_nodes.py @@ -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 @@ -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) @@ -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( @@ -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. @@ -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) @@ -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: @@ -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: @@ -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 diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index a87514866d..c1c7af36da 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -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 @@ -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() @@ -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 ) @@ -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 @@ -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 ) @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 @@ -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 @@ -4123,7 +4123,7 @@ def _infer( InferenceContext | None, None, ], - Generator[NodeNG, None, None], + Generator[NodeNG], ] ] = protocols.assign_assigned_stmts @@ -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 diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index ed46a7a115..3a482f3cc9 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -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. diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py index 48a1ccfc3a..af3b9d39a8 100644 --- a/astroid/nodes/scoped_nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes/scoped_nodes.py @@ -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 @@ -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): @@ -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. @@ -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 diff --git a/astroid/objects.py b/astroid/objects.py index f94d1f16ff..2d12f59805 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -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 diff --git a/astroid/protocols.py b/astroid/protocols.py index 8e90ddab58..bacb786a99 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -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 ( @@ -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 @@ -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) @@ -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 @@ -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. """ @@ -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. """ @@ -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. """ @@ -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. """ diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index 70ea53718a..b783885019 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -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)