Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a gi_code attr to generators #43254

Closed
collinwinter mannequin opened this issue Apr 19, 2006 · 7 comments
Closed

Add a gi_code attr to generators #43254

collinwinter mannequin opened this issue Apr 19, 2006 · 7 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@collinwinter
Copy link
Mannequin

collinwinter mannequin commented Apr 19, 2006

BPO 1473257
Nosy @gvanrossum, @birkenfeld, @pjeby
Files
  • gi_code.patch: Add gi_code attr to generators, against r46040
  • 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

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-01-26.14:14:40.316>
    created_at = <Date 2006-04-19.21:39:28.000>
    labels = ['interpreter-core']
    title = 'Add a gi_code attr to generators'
    updated_at = <Date 2008-01-26.14:14:40.315>
    user = 'https://bugs.python.org/collinwinter'

    bugs.python.org fields:

    activity = <Date 2008-01-26.14:14:40.315>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-01-26.14:14:40.316>
    closer = 'georg.brandl'
    components = ['Interpreter Core']
    creation = <Date 2006-04-19.21:39:28.000>
    creator = 'collinwinter'
    dependencies = []
    files = ['7185', '7186']
    hgrepos = []
    issue_num = 1473257
    keywords = ['patch']
    message_count = 7.0
    messages = ['50081', '50082', '50083', '50084', '61270', '61476', '61710']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'georg.brandl', 'collinwinter', 'pje']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1473257'
    versions = ['Python 2.6']

    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented Apr 19, 2006

    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.

    @collinwinter collinwinter mannequin assigned pjeby Apr 19, 2006
    @collinwinter collinwinter mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 19, 2006
    @collinwinter collinwinter mannequin assigned pjeby Apr 19, 2006
    @collinwinter collinwinter mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 19, 2006
    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented Apr 29, 2006

    Logged In: YES
    user_id=1344176

    I've updated the patch; it's now against SVN r45808.

    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=849994

    Phillip, do you have an opinion on this one?

    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented May 18, 2006

    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?

    @birkenfeld
    Copy link
    Member

    Guido, do you have an opinion? Seems like a nonproblematic and probably
    useful change for 2.6.

    @birkenfeld birkenfeld assigned gvanrossum and unassigned pjeby Jan 20, 2008
    @gvanrossum
    Copy link
    Member

    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.)

    @birkenfeld
    Copy link
    Member

    Reformatted the patch to use tabs and committed as r60324.

    @birkenfeld birkenfeld assigned birkenfeld and unassigned gvanrossum Jan 26, 2008
    @birkenfeld birkenfeld assigned birkenfeld and unassigned gvanrossum Jan 26, 2008
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants