summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2023-02-23 16:01:10 -0500
committerGitHub <noreply@github.com>2023-02-23 22:01:10 +0100
commit8f24c69d3f6f9ff19d4b867c840bc1dd560ddddb (patch)
treee4466d030b95e4189bc343a26d77b907af9ab88b /pylint
parentd064010c324cb20a83928c5bae02386ea73fe8d7 (diff)
downloadpylint-git-8f24c69d3f6f9ff19d4b867c840bc1dd560ddddb.tar.gz
Only count obviously non-terminating while-loops as return-ended (#8292)
Diffstat (limited to 'pylint')
-rw-r--r--pylint/checkers/refactoring/refactoring_checker.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py
index 0caa2fbb5..5aaedf794 100644
--- a/pylint/checkers/refactoring/refactoring_checker.py
+++ b/pylint/checkers/refactoring/refactoring_checker.py
@@ -20,6 +20,7 @@ from astroid.util import Uninferable
from pylint import checkers
from pylint.checkers import utils
+from pylint.checkers.base.basic_error_checker import _loop_exits_early
from pylint.checkers.utils import node_frame_class
from pylint.interfaces import HIGH, INFERENCE, Confidence
@@ -1945,10 +1946,12 @@ class RefactoringChecker(checkers.BaseTokenChecker):
return True
except astroid.InferenceError:
pass
- # Avoid the check inside while loop as we don't know
- # if they will be completed
if isinstance(node, nodes.While):
- return True
+ # A while-loop is considered return-ended if it has a
+ # truthy test and no break statements
+ return (node.test.bool_value() and not _loop_exits_early(node)) or any(
+ self._is_node_return_ended(child) for child in node.orelse
+ )
if isinstance(node, nodes.Raise):
return self._is_raise_node_return_ended(node)
if isinstance(node, nodes.If):