You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NEWS.diff: Add an item to Misc/NEWS about the gi_code attr, against r46040
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
title='Add a gi_code attr to generators'updated_at=<Date2008-01-26.14:14:40.315>user='https://bugs.python.org/collinwinter'
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:
>>> g = f()
>>> g.gi_code is f.func_code
I noticed some whitespace issues in the patch, but apart from that I
have no objection. (Not any particular enthusiasm, I have to admit -- I
don't quite get the use case, but as Georg remarks, it seems harmless.)