[Python-ideas] PEP 479: Change StopIteration handling inside generators
Chris Angelico
rosuav at gmail.com
Thu Nov 20 11:43:54 CET 2014
On Thu, Nov 20, 2014 at 9:13 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 20 November 2014 15:54, Chris Angelico <rosuav at gmail.com> wrote:
>>
>> On Thu, Nov 20, 2014 at 2:44 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> >
>> > I poked around a bit in the code and managed to come up with this. It
>> > doesn't chain the previous exception, so the traceback is a little
>> > scanty, but it does turn a StopIteration into a RuntimeError. (It
>> > might also leak the original StopIteration. I'm not sure.) Prior to
>> > this patch, I had 377 of 390 tests passing flawlessly and no failures
>> > (just skips and warnings); with this applied, six failures.
>> >
>>
>> With the attached demo patch, all tests pass except test_generators,
>> which explicitly tests stuff about the correlation between return and
>> StopIteration. There's the contextlib changes, a couple of places that
>> were raising StopIteration and should be returning, and a couple that
>> were letting StopIteration bubble and now need to catch it and return.
>> I've deliberately not followed PEP 8 here, in the interests of
>> minimizing diff size; in several cases, blocks of code ought to be
>> indented a level, but I cheated and created a half-indentation to show
>> how little actually changes.
>
>
> Thanks Chris - could you make a tracker issue and attach this there?
http://bugs.python.org/issue22906
ChrisA
More information about the Python-ideas
mailing list