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 terry.reedy
Recipients chris.jerdonek, docs@python, ncoghlan, terry.reedy
Date 2012-07-28.06:54:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Up until today, I had assumed that it was the generator.__next__ method that was associated with the compiled body. But in writing my response, I investigated and discovered

>>> def gf(): yield None

>>> gf().gi_code is gf.__code__

Then i realized that the simple call protocal -- a callable is an object with an executable __call__ method -- makes the magic simpler than I thought. Generator functions must have a special __call__ method that simply creates and returns a generator instance with the code object attached (instead of executing the code).

Since code objects are referred to in various places (compile(), exec(), probably def statement doc), I agree that there should be a minimal glossary entry. One can't really understand generator functions and generators without knowing that def statements create both a function object and an attached code object, but that they can operate somewhat separately.
Date User Action Args
2012-07-28 06:54:53terry.reedysetrecipients: + terry.reedy, ncoghlan, chris.jerdonek, docs@python
2012-07-28 06:54:53terry.reedysetmessageid: <>
2012-07-28 06:54:52terry.reedylinkissue15457 messages
2012-07-28 06:54:52terry.reedycreate