homepage

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.

classification
Title: Add a gi_code attr to generators
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: collinwinter, georg.brandl, gvanrossum, pje
Priority: normal Keywords: patch

Created on 2006年04月19日 21:39 by collinwinter, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gi_code.patch collinwinter, 2006年05月18日 17:11 Add gi_code attr to generators, against r46040
NEWS.diff collinwinter, 2006年05月18日 17:12 Add an item to Misc/NEWS about the gi_code attr, against r46040
Messages (7)
msg50081 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2006年04月19日 21:39
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.
msg50082 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2006年04月29日 21:11
Logged In: YES 
user_id=1344176
I've updated the patch; it's now against SVN r45808.
msg50083 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006年04月30日 11:17
Logged In: YES 
user_id=849994
Phillip, do you have an opinion on this one?
msg50084 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2006年05月18日 17:13
Logged In: YES 
user_id=1344176
In addition to updating the main patch to r46040, I've
included a diff against Misc/NEWS to make mention of the
gi_code attribute.
Any thoughts on getting this into 2.5a3?
msg61270 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008年01月20日 11:18
Guido, do you have an opinion? Seems like a nonproblematic and probably
useful change for 2.6.
msg61476 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008年01月22日 01:58
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.)
msg61710 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008年01月26日 14:14
Reformatted the patch to use tabs and committed as r60324.
History
Date User Action Args
2022年04月11日 14:56:16adminsetgithub: 43254
2008年01月26日 14:14:40georg.brandlsetstatus: open -> closed
assignee: gvanrossum -> georg.brandl
resolution: accepted
messages: + msg61710
2008年01月22日 01:58:17gvanrossumsetmessages: + msg61476
2008年01月20日 11:18:08georg.brandlsetassignee: pje -> gvanrossum
messages: + msg61270
nosy: + gvanrossum
2006年04月19日 21:39:28collinwintercreate

AltStyle によって変換されたページ (->オリジナル) /