[Python-Dev] Integrating PEP 310 with PEP 340

Guido van Rossum gvanrossum at gmail.com
Thu Apr 28 00:16:06 CEST 2005


[Nick Coghlan]
> This is my attempt at a coherent combination of what I like about both proposals
> (as opposed to my assortment of half-baked attempts scattered through the
> existing discussion).
> 
> PEP 340 has many ideas I like:
>    - enhanced yield statements and yield expressions
>    - enhanced continue and break
>    - generator finalisation
>    - 'next' builtin and associated __next__() slot
>    - changes to 'for' loop
> 
> One restriction I don't like is the limitation to ContinueIteration and
> StopIteration as arguments to next(). The proposed semantics and conventions for
> ContinueIteration and StopIteration are fine, but I would like to be able to
> pass _any_ exception in to the generator, allowing the generator to decide if a
> given exception justifies halting the iteration.

I'm close to dropping this if we can agree on the API for passing
exceptions into __next__(); see the section "Alternative __next__()
and Generator Exception Handling" that I just added to the PEP.

> The _major_ part I don't like is that the block statement's semantics are too
> similar to those of a 'for' loop. I would like to see a new construct that can
> do things a for loop can't do, and which can be used in _conjunction_ with a for
> loop, to provide greater power than either construct on their own.

While both 'block' and 'for' are looping constructs, their handling of
the iterator upon premature exit is entirely different, and it's hard
to reconcile these two before Python 3000.

> PEP 310 forms the basis for a block construct that I _do_ like. The question
> then becomes whether or not generators can be used to write useful PEP 310 style
> block managers (I think they can, in a style very similar to that of the looping
> block construct from PEP 340).

I've read through your example, and I'm not clear why you think this
is better. It's a much more complex API with less power. What's your
use case? Why should 'block' be disallowed from looping? TOOWTDI or do
you have something better?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list