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

Nick Coghlan ncoghlan at gmail.com
Sat Nov 22 15:31:12 CET 2014


On 22 Nov 2014 02:51, "Antoine Pitrou" <solipsis at pitrou.net> wrote:
>
> On Fri, 21 Nov 2014 05:47:58 -0800
> Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
> >
> > Another issue is that it breaks the way I and others have taught for
years that generators are a kind of iterator (an object implementing the
iterator protocol) and that a primary motivation for generators is to
provide a simpler and more direct way of creating iterators.  However,
Chris explained that, "This proposal causes a separation of generators and
iterators, so it's no longer possible to pretend that they're the same
thing."  That is a major and worrisome conceptual shift.
>
> I agree with Raymond on this point.

A particularly relevant variant of the idiom is the approach of writing
"__iter__" directly as a generator, rather than creating a separate custom
iterator class. In that context, the similarities between the __iter__
implementation and the corresponding explicit __next__ implementation is a
beneficial feature.

I'm definitely coming around to the point of view that, even if we wouldn't
design it the way it currently works given a blank slate, the alternative
design doesn't provide sufficient benefit to justify the cost of changing
the behaviour & getting people to retrain their brains.

Cheers,
Nick.

>
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141123/76b8009b/attachment.html>


More information about the Python-Dev mailing list