[Python-Dev] PEP 343 - Abstract Block Redux

Shane Hathaway shane at hathawaymix.org
Mon May 16 20:29:08 CEST 2005


Greg Ewing wrote:
> Brett C. wrote:
> 
> 
>>Nick's was obviously directly against looping, but, with no offense to Nick,
>>how many other people were against it looping?  It never felt like it was a
>>screaming mass with pitchforks but more of a "I don't love it, but I can deal"
>>crowd.
> 
> 
> My problem with looping was that, with it, the semantics
> of a block statement would be almost, but not quite,
> exactly like those of a for-loop, which seems to be
> flying in the face of TOOWTDI. And if it weren't for
> the can't-finalise-generators-in-a-for-loop backward
> compatibility problem, the difference would be even
> smaller.

I wonder if we should reconsider PEP 340, with one change: the block
iterator is required to iterate exactly once.  If it iterates more than
once or not at all, the interpreter raises a RuntimeError, indicating
the iterator can not be used as a block template.  With that change,
'break' and 'continue' will obviously affect 'for' and 'while' loops
rather than block statements.

Advantages of PEP 340, with this change, over PEP 343:

- we reuse a protocol rather than invent a new protocol.

- decorators aren't necessary.

- it's a step toward more general flow control macros.

At first I wasn't sure people would like the idea of requiring iterators
to iterate exactly once, but I just realized the other PEPs have the
same requirement.

Shane


More information about the Python-Dev mailing list