Terry J. Reedy <tjre...@udel.edu> added the comment:

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.

----------
nosy: +terry.reedy
versions: +Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15457>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to