[Python-ideas] Possible PEP 380 tweak

Nick Coghlan ncoghlan at gmail.com
Thu Oct 28 14:44:31 CEST 2010

On Thu, Oct 28, 2010 at 9:46 AM, Guido van Rossum <guido at python.org> wrote:
> Nick & Jacob,
> Unfortunately other things are in need of my attention and I am
> quickly lagging behind on this thread.
> I'll try to respond to some issues without specific quoting.
> If GeneratorReturn and finish() can be implemented in pure user code,
> then I think it should be up to every (framework) developer to provide
> their own API, using whatever constraints they chose. Without specific
> use cases it's hard to reason about API design. Still, I think it is
> reasonable to offer some basic behavior on the generator object, and I
> still think that the best compromise here is to let g.close() extract
> the return value from StopIteration if it catches it. If a framework
> decides not to use this, fine. For a user working without a framework
> this is still just a little nicer than having to figure out the
> required logic yourself.

Yep, we've basically agreed on that as the way forward as well. We
have a small tweak to suggest for PEP 380 to avoid losing the return
value from inner close() calls, and I've cc'ed Greg directly on the
relevant message in order to move that idea forward (and bring the
python.org version of the PEP up to date with the last posted version
as well).

That should provide a solid foundation for experimentation in user
code in 3.3 without overcomplicating PEP 380 with stuff that will
probably end up being YAGNI.

> I would be in favor of adding an introspection API to distinguish
> these four states and I think it would be a fine thing to add to
> Python 3.2 if anyone finds the time to produce a patch (Nick? You
> showed what these boil down to.)

I've created a tracker issue proposing a simple
inspect.getgeneratorstate() function (issue 10220).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list