From cc9054101ca938f0fdc91d963248fd9e4f16cc37 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 10 Jun 2022 16:50:59 -0400 Subject: [PATCH] avoid two iterations --- pylint/checkers/base/basic_checker.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pylint/checkers/base/basic_checker.py b/pylint/checkers/base/basic_checker.py index a3f583c4c5..79e4191cbc 100644 --- a/pylint/checkers/base/basic_checker.py +++ b/pylint/checkers/base/basic_checker.py @@ -321,10 +321,13 @@ def _check_using_constant_test( elif isinstance(test, nodes.Call): inferred_call = utils.safe_infer(test.func) if isinstance(inferred_call, nodes.FunctionDef): - return_nodes = list(inferred_call._get_return_nodes_skip_functions()) - if return_nodes and all( - isinstance(n.value, nodes.GeneratorExp) for n in return_nodes - ): + all_returns_were_generator = None + for return_node in inferred_call._get_return_nodes_skip_functions(): + if not isinstance(return_node.value, nodes.GeneratorExp): + all_returns_were_generator = False + break + all_returns_were_generator = True + if all_returns_were_generator: self.add_message( "using-constant-test", node=node, confidence=INFERENCE )