[Python-ideas] SyntaxWarning for for/while/else without break or return?

Terry Reedy tjreedy at udel.edu
Thu Oct 8 21:44:17 CEST 2009

Masklinn wrote:
> On 8 Oct 2009, at 15:44 , Gerald Britton wrote:

>> re syntax: There are at least three ways to exit a for-loop early:
>> break, return and raise (explicit or implicit).  Would this code
>> generate a warning? (I hope not)
> Both would, because in both cases the `else:` clause serves no purpose 
> whatsoever. It's noise.

To you, but not to Gerald or me.

To me, this is a formatting style issue that the *compiler* should keeps 
its hands off of. As I said at the begining of this thread, this issue 
is appropriate for separate and optional code/style checkers like 

Suppose I have

for i is s:
   if c(i): break

I decide *maybe* I do not want do_c in the function, so I comment out 
the last line and change 'break' to 'return'. You and the OP would force 
ME to also comment out or delete the 'else:' and dedent 'do_b' for no 
functional reason but merely to satisy YOUR esthetic style preference.

To me, that attitude is pretty obnoxious.

Terry Jan Reedy

More information about the Python-ideas mailing list