(original) (raw)
I've made some updates to the PEP:
- added 19-Nov-2014 to Post-History- added a link to http://bugs.python.org/issue22906 which has a proof-of-concept patch
However I don't see much evidence that the current behavior is \*better\* than the proposal -- I see the current behavior as a definite wart, and I have definitely seen people struggle to debug silent early loop termination due to an "escaped" StopIteration.
That said, I think for most people the change won't matter, some people will have to apply one of a few simple fixes, and a rare few will have to rewrite their code in a non-trivial way (sometimes this will affect "clever" libraries).
That said, I think for most people the change won't matter, some people will have to apply one of a few simple fixes, and a rare few will have to rewrite their code in a non-trivial way (sometimes this will affect "clever" libraries).
Oh, and it would also be nice if the PEP included some suggested words that 3rd party educators can use to explain the relationship between StopIteration and generators in a healthier way (preferably a way that also applies to older versions).
Chris, are you up to drafting these additions?
On Thu, Nov 20, 2014 at 2:05 AM, Nick Coghlan <ncoghlan@gmail.com> wrote:
I think my suggestion was something like "from \_\_future\_\_ import generator\_return".On 20 November 2014 06:15, Benjamin Peterson <benjamin@python.org> wrote:
On Wed, Nov 19, 2014, at 15:10, Guido van Rossum wrote:
\> There's a new PEP proposing to change how to treat StopIteration bubbling
\> up out of a generator frame (not caused by a return from the frame). The
\> proposal is to replace such a StopIteration with a RuntimeError (chained
\> to
\> the original StopIteration), so that only \*returning\* from a generator
\> (or
\> falling off the end) causes the iteration to terminate.
\>
\> The proposal unifies the behavior of list comprehensions and generator
\> expressions along the lines I had originally in mind when they were
\> introduced. It renders useless/illegal certain hacks that have crept into
\> some folks' arsenal of obfuscated Python tools.
\>
\> In Python 3.5 the proposed change is conditional on:
\>
\> from \_\_future\_\_ import replace\_stopiteration\_in\_generators
Drive-by comment: This seems like a terribly awkward name. Could a
shorter and sweeter name not be found?
I saw that style as somewhat similar to "from \_\_future\_\_ import division" - it just tells you what the change affects (in this case, returning from generators), while requiring folks to look up the documentation to find out the exact details of the old behaviour and the new behaviour.Cheers,
Nick.
--
--Guido van Rossum (python.org/\~guido)