[Python-ideas] for/else syntax
Nick Coghlan
ncoghlan at gmail.com
Fri Oct 2 17:29:56 CEST 2009
Stephen J. Turnbull wrote:
> Yuvgoog Greenle writes:
>
> > I think I understand what you're saying and I just don't understand how it
> > pertains to for..else. Specifically I would like an explanation about why
> > the following quote is nonsense to you.
>
> I didn't say it was nonsense and I didn't mean it was nonsense.
>
> I can see no reason at all why PyLint wouldn't warn about "breakless
> for-else". "raise StopIteration" and "if __debug__: break" *may* be
> sufficient reason Python itself shouldn't be too noisy, but for sure
> PyLint should warn about it.
raise StopIteration in the body of the for loop will escape, just like
any other suggestion.
However, Gerald's point that the else clause can also be used to give
the iteration variable a "default" value (with nary a break in sight) in
addition to the more traditional search loop idiom is enough to convince
me that the compiler should stay out of this one.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list