[Python-Dev] PEP 479: Change StopIteration handling inside generators

Ethan Furman ethan at stoneleaf.us
Sun Nov 23 03:00:18 CET 2014


On 11/22/2014 05:11 PM, Raymond Hettinger wrote:
>> On Nov 22, 2014, at 2:45 PM, Chris Angelico wrote:
>>
>> Does your middleware_generator work with just a single element,
>> yielding either one output value or none?
> 
> I apologize if I didn't make the point clearly.  The middleware example was 
> just simple outline of calling next(), doing some processing, and yielding a
> result while letting the StopIteration float through from the next() call.

[middleware example]

    def middleware_generator(source_generator):
        it = source_generator()
        input_value = next(it)
        output_value = do_something_interesting(input_value)
        yield output_value

The point that Chris made that you should be refuting is this one:

>> What happens if do_something_interesting happens to raise
>> StopIteration? Will you be surprised that this appears identical to
>> the source generator yielding nothing?

--
~Ethan~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141122/4b33ea6b/attachment.sig>


More information about the Python-Dev mailing list