Message166631
| 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 |
<1343458493.46.0.79123635734.issue15457@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|