Message166631
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__
True
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:53 | terry.reedy | set | recipients:
+ terry.reedy, ncoghlan, chris.jerdonek, docs@python |
2012-07-28 06:54:53 | terry.reedy | set | messageid: <1343458493.46.0.79123635734.issue15457@psf.upfronthosting.co.za> |
2012-07-28 06:54:52 | terry.reedy | link | issue15457 messages |
2012-07-28 06:54:52 | terry.reedy | create | |
|