[Python-ideas] SyntaxWarning for for/while/else without break or return?
Georg Brandl
g.brandl at gmx.net
Thu Oct 8 21:50:05 CEST 2009
Stephen J. Turnbull schrieb:
> geremy condra writes:
>
> > I grant you that compilers *shouldn't* be smarter than programmers,
> > but I highly doubt that any program including an extraneous else
> > clause is "working according to specifications", and that's the point
> > of this proposal.
>
> Actually, I can imagine someone developing a style where a redundant
> else was used to indicate "this is part of/cleanup of the for loop,
> and should go with it in any refactoring".
>
> Say, in a program that speaks SMTP:
>
> for line in line_factory:
> smtp_send(line + "\n")
> else:
> smtp_send(".\n")
Usually, that effect can be created by newlines:
for line in line_factory:
smtp_send(line + "\n")
smtp_send(".\n")
more code goes here
I'm not sure myself whether I like generating warnings for valid syntax,
but in the often-misunderstood case of for/else, I think it would be
reasonable.
Georg
More information about the Python-ideas
mailing list