New check: break
at the top of while True
loop
#8015
Labels
Enhancement ✨
Improvement to a component
Good first issue
Friendly and approachable by new contributors
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
Milestone
Current problem
A not-uncommon pattern is to check some condition at the top of a
while True
loop and break if the condition is met:There is an instance of this in the Pylint codebase.
Desired solution
It would be more straightforward and less verbose to negate the condition and move it into the
while
expression:Add a new check for the following circumstance:
while
loop withTrue
condition (or more generally, constant condition);if
statement; andif
body is abreak
statement.In this case, emit a suggestion to negate the condition and move it to the
while
.I don't know what the name of the warning should be. Suggestions welcome!
Additional context
No response
The text was updated successfully, but these errors were encountered: