[Python-Dev] Merging PEP 310 and PEP 340-redux?
Guido van Rossum
gvanrossum at gmail.com
Fri May 13 18:29:19 CEST 2005
[Steven Bethard]
> +0. I'm not thoroughly convinced that generators are that much easier
> to read than a class. But I don't find them hard to read, and I think
> it would only take a little effort to learn that generators might not
> always be intended to build iterators.
I am proposing (like Phillip Eby in his response to PEP 340) to use a
special decorator that turns a generator into a "do-template", so the
intention is evident from the generator declaration.
> If we do support generators in do-statements, I'd like their
> __enter__() and __exit__() methods (if possible) to have semantics
> like Nick Coghlan suggested[1], so that:
> * __enter__() raises an exception if next() has already been called, and
> * __exit__() raises an exception if StopIteration is not raised
I guess you missed my post where I gave the code for the decorator; it
does exactly that.
> The simpler semantics give you the difference between a normal exit
> and an exceptional exit. I'd like to see an example that needs to
> know the difference between block completion exit and a
> break/continue/return exit before I'd want to make PEP 340 redux this
> much more complex.
I agreed to that in my response to Phillip Eby. I do want to pass the
exception into __exit__ so that it can be logged, for example.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list