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

2014年11月21日 10:22:00 -0800

On Fri, Nov 21, 2014 at 8:47 AM, Antoine Pitrou <[email protected]> wrote:
> On 2014年11月21日 05:47:58 -0800
> Raymond Hettinger <[email protected]> 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.
>
Pretending they're the same thing has always been fraught with subtle
errors. From the *calling* side a generator implements the same protocol as
any other iterator (though it also has a few others -- send(), throw(),
close()). However *inside* they are not at all similar -- generators
produce a value is done through "yield", __next__() methods use return.
Even if we end up rejecting the PEP we should campaign for better
understanding of generators. Raymond may just have to fix some of his
examples.
-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to