[docs] [issue15457] consistent treatment of generator terminology
Terry J. Reedy
report at bugs.python.org
Sat Jul 28 08:54:53 CEST 2012
Terry J. Reedy <tjreedy at udel.edu> added the comment:
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.
Python tracker <report at bugs.python.org>
More information about the docs