[code-quality] pylint: Else clause on a loop without break statement

Carl Crowder carl.crowder at gmail.com
Sun Jan 12 16:13:03 CET 2014


This came up once before, and I think the reasoning is that a for loop
without a break statement means the 'else' is redundant.

In your example, you can remove the 'else' and it would be functionally the
same.


On 12 January 2014 15:57, Kay Hayen <kay.hayen at gmail.com> wrote:

>
> Hello,
>
> often I write code like this:
>
> def _areConstants(expressions):
>     for expression in expressions:
>         if not expression.isExpressionConstantRef():
>             return False
>
>         if expression.isMutable():
>             return False
>     else:
>         return True
>
> That is to search in an iterable, and return based on finding something,
> or returning in the alternative, I specifically prefer the "else:" branch
> over merely putting it after the "for" loop.
>
> This triggers the above message, which I consider flawed, because as soon
> as there is a "raise", or "return", that should be good enough as well.
> Basically any aborting statement, not only break.
>
> I wanted to hear your opinion on this, pylint bug, or only in my mind.
>
> Yours,
> Kay
> _______________________________________________
> code-quality mailing list
> code-quality at python.org
> https://mail.python.org/mailman/listinfo/code-quality
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20140112/25310dfa/attachment.html>


More information about the code-quality mailing list