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 collinwinter
Recipients
Date 2006-04-19.21:39:28
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
In the test suite for one of my packages, I've used
something like gen.gi_frame.f_code.co_name to help make
human-readable assertions about when certain generators
are run deep inside the application. This was possible
because Python 2.4 guaranteed that gi_frame was always
a frame instance, even after the generator exhausted
itself. In Python 2.5, however, gi_frame is None when
the generator has run till exhaustion, meaning that I
can't always get to f_code.co_name.

I'd like to add a gi_code attribute to generators that
would allow users to access the code object behind the
generator, even when gi_frame is None. This attribute
would be read-only and would follow this rule:

>>> def f():
...     yield 5
...
>>> g = f()
>>> g.gi_code is f.func_code
True
>>>

The attached patch (against r45570) implements the
proposed attribute (in Include/genobject.h and
Objects/genobject.c) and adds test cases to
Lib/test/test_generators.py for this attribute.
History
Date User Action Args
2007-08-23 15:48:25adminlinkissue1473257 messages
2007-08-23 15:48:25admincreate