On 18 septembre 05:33, Michael Foord wrote:
On 18 September 2013 02:39, Skip Montanaro <skip@pobox.com> wrote:
I still think you're missing the point of my original post. A return is as good as a break when considering early exit from a loop. The pylint code only checks for the presence of a break statement, but the test cases clearly show a case with a return statement. The test functions even include docstrings which state that.
It's not considering the exit from the loop it's considering the entry to the else clause. A break would continue past the body of the loop without entering the else clause (so the else would have a meaning - only enter this code if we haven't hit break). Without a break the else clause will always be entered if the loop terminates normally, so the else is useless. Just putting the return immediately after the loop is functionally identical.
That you have some early returns inside the body of the loop is irrelevant
Yep, that's the point of this check so IMO Pylint doesn't have to be changed. May Torsten or someone else from Google which has contributed this check may confirm this is the expected behaviour. Skip, regarding the test you found: def test_return_for(): """else + return is accetable.""" for i in range(10): if i % 2: return i else: print 'math is broken' the docstring doomed you: the else is actually warned here (see associated message file in test/messages/func_useless_else_on_loop.txt). I'll fix that. -- Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42) Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations Développement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org