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-27.23:48:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1343432934.42.0.704753701284.issue15457@psf.upfronthosting.co.za>
In-reply-to
Content
I think the current entry calling a generator function a generator is wrong, so I appreciate your patch. Generator functions return instances of class 'generator'*. I personally refer to generators as generator-iterators about as often as I refer to lists as list-sequences. (Generators implement the iterator protocol; lists implement the sequence protocol.)

* I personally think of a generator function as defining a virtual subclass of class generator and returning instances of that (vitual) subclass. The gf does this# by setting the gi_code attribute of instances to the code object compiled from its body. (Or perhaps it calls the generator class with its code object as parameter. In any case, this is what the special gf.__call__ method does instead of executing its code attribute. The call protocol makes this magic easy.) The generator subclass, then, is all instances with the same gi_code attribute. The name of the 'subclass' is the name of the generator function, which is also g.gi_code.co_name.

# Although 'gi_code' does not have a leading underscore, I am not sure whether it is intended to be public or if the mechanism is CPython specific. It *is' the only way to get the gf/subclass name from the generator.

What I think still needs correction is "generator then controls the execution of a generator function". The generator function has already run to create the generator. What is controlled is the execution of the code object compiled from the body of a gf. And the 'generator function' in question is not just 'a generator function' but 'the generator function that created the generator'.

So I suggest as more correct something like "generator then controls the execution of the [code object compiled from the] body of the generator function that created it" The part in [] is true but might be omitted if it seems too much in the context.
History
Date User Action Args
2012-07-27 23:48:54terry.reedysetrecipients: + terry.reedy, ncoghlan, chris.jerdonek, docs@python
2012-07-27 23:48:54terry.reedysetmessageid: <1343432934.42.0.704753701284.issue15457@psf.upfronthosting.co.za>
2012-07-27 23:48:53terry.reedylinkissue15457 messages
2012-07-27 23:48:53terry.reedycreate