This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pje
Date 2005-06-18.23:08:41
SpamBayes Score
Marked as misclassified
The attached patch implements code and test changes for:

* yield expressions
* bare yield (short for yield None)
* yield in try/finally
* generator.send(value) (send value into generator;
substituted for PEP 342's next(arg))
* generator.throw(typ[,val[,tb]]) (raise error in
* generator.close() (per PEP 343)
* GeneratorExit built-in exception type
* generator.__del__ (well, the C equivalent)
* All necessary mods to the compiler, parser module,
and Python 'compiler' package to support these changes.

It was necessary to change a small part of the eval
loop (well, the initialization, not the loop) and the
gc module's has_finalizer() logic in order to support a
C equivalent to __del__.  Specialists in these areas
should probably scrutinize this patch!

There is one additional implementation detail that was
not contemplated in either PEP. in order to prevent
used-up generators from retaining unnecessary
references to their frame's contents, I set the
generator's gi_frame member to None whenever the
generator finishes normally or with an error.  Thus, an
exhausted generator cannot be part of a cycle, and it
releases its frame object sooner than in previous
Python versions.  For generators used only in a direct
"for" loop, this makes no difference, but for
generators used with the iterator protocol (i.e.
"") from Python, this avoids stranding the
generator's frame in a traceback cycle.
Date User Action Args
2007-08-23 15:43:18adminlinkissue1223381 messages
2007-08-23 15:43:18admincreate