pylint #81378 Suggested rule: Loop has else clause but no break. [validation pending]
The for..else... and while...else... constructs are known to be confusing.
(For example, see this article and its comments: http://nedbatchelder.com/blog/201110/forelse.html)
That has lead one person (a commenter on that article) to develop a stand-alone tool to detect when someone has included an else clause without having a corresponding break statement.
Such a clause is not illegal, but suggests the developer may be confused. It is equivalent to the same code simply being after the loop.
NB: It won't catch all such confusions, but it is a start.
|appeared in||<not specified>|
|closed by||#962fff72742b Emit a warning for loops that have an else clause but no break or return.|
|patch||Emit a warning for loops that have an else clause but no break or return. [applied]|