[Python-ideas] SyntaxWarning for for/while/else wi thout break or return?
Stephen J. Turnbull
stephen at xemacs.org
Fri Oct 9 14:13:59 CEST 2009
Steven D'Aprano writes:
> That makes no sense. If there's no difference between:
>
> for x in seq:
> pass
> else:
> whatever()
>
> and
>
> for x in seq:
> pass
> whatever()
>
> then what could the warning save you from?
The warning can save me from the brain fart that has been repeated
over and over in this thread: thinking that there *is* a difference.
This thread is ample evidence that people can and do misread and
miswrite that construct *even in a context where they are forewarned
that they are discussing an easily misused construct*.
> Perhaps you're thinking of the following:
Stop trying to read my mind. What you should be reading is some of
the posts in this thread explaining that
for x in seq:
pass
else:
whatever()
means
if seq:
for x in seq:
pass
else:
whatever()
or similar ... *after* Nick's explanation that the for/break/else
idiom for search is the only semantically interesting form.
More information about the Python-ideas
mailing list