[Python-Dev] Proposed alternative to __next__ and __exit__
oren.tirosh at gmail.com
Sat May 7 18:56:28 CEST 2005
I suggest using a variation on the consumer interface, as described by
Fredrik Lundh at http://effbot.org/zone/consumer.htm :
.next() -- stays .next()
.__next__(arg) -- becomes .feed(arg)
.__exit__(StopIteration, ...) -- becomes .close()
.__exit__(..,..,..) -- becomes .feed(exc_info=(..,..,..))
Extensions to effbot's original consumer interface:
1. The .feed() method may return a value
2. Some way to raise an exception other than StopIteration inside the
generator/consumer function. The use of a keyword argument to .feed
is just an example. I'm looking for other suggestions on this one.
No new builtins. No backward-compatibility methods and wrappers.
Yes, it would have been nicer if .next() had been called __next__() in
the first place. But at this stage I feel that the cost of "fixing" it
far outweighs any perceived benefit.
so much for "uncontroversial" parts! :-)
On 5/6/05, Guido van Rossum <gvanrossum at gmail.com> wrote:
> [Steven Bethard]
> > So, just to make sure, if we had another PEP that contained from PEP 340:
> > * Specification: the __next__() Method
> > * Specification: the next() Built-in Function
> > * Specification: a Change to the 'for' Loop
> > * Specification: the Extended 'continue' Statement
> > * the yield-expression part of Specification: Generator Exit Handling
> > would that cover all the pieces you're concerned about?
> > I'd be willing to break these off into a separate PEP if people think
> > it's a good idea. I've seen very few complaints about any of these
> > pieces of the proposal. If possible, I'd like to see these things
> > approved now, so that the discussion could focus more directly on the
> > block-statement issues.
> I don't think it's necessary to separate this out into a separate PEP;
> that just seems busy-work. I agree these parts are orthogonal and
> uncontroversial; a counter-PEP can suffice by stating that it's not
> countering those items nor repeating them.
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/oren.tirosh%40gmail.com
More information about the Python-Dev