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

2.3 inspect.getframeinfo wrong tb line numbers #40257

Closed
rgbecker mannequin opened this issue May 15, 2004 · 6 comments
Closed

2.3 inspect.getframeinfo wrong tb line numbers #40257

rgbecker mannequin opened this issue May 15, 2004 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@rgbecker
Copy link
Mannequin

rgbecker mannequin commented May 15, 2004

BPO 954364
Nosy @akuchling
Files
  • python-2.4a0-954364.patch: patch for 2.4a0 inspect.py test/test_inspect.py
  • inspect_getinnerframes_bug.py: Demonstrate inspect.getinnerframes bug
  • inspect.patch2
  • inspect.patch3: Merged amk's patch & delta to test_inspect.py
  • 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/akuchling'
    closed_at = <Date 2004-06-05.14:16:07.000>
    created_at = <Date 2004-05-15.08:41:29.000>
    labels = ['library']
    title = '2.3 inspect.getframeinfo wrong tb line numbers'
    updated_at = <Date 2004-06-05.14:16:07.000>
    user = 'https://bugs.python.org/rgbecker'

    bugs.python.org fields:

    activity = <Date 2004-06-05.14:16:07.000>
    actor = 'akuchling'
    assignee = 'akuchling'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2004-05-15.08:41:29.000>
    creator = 'rgbecker'
    dependencies = []
    files = ['1282', '1283', '1284', '1285']
    hgrepos = []
    issue_num = 954364
    keywords = []
    message_count = 6.0
    messages = ['20807', '20808', '20809', '20810', '20811', '20812']
    nosy_count = 2.0
    nosy_names = ['akuchling', 'rgbecker']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue954364'
    versions = ['Python 2.3']

    @rgbecker
    Copy link
    Mannequin Author

    rgbecker mannequin commented May 15, 2004

    inspect.getframeinfo always uses f_lineno even when
    passed a tb. In practice it is not always true that

    tb.tb_frame.f_lineno==tb.tb_lineno

    so user functions like inspect.getinnerframes (and
    hence cgitb) will get wrong information back sometimes.

    I fixed this using the attached patch.

    This script illustrates via cgitb.
    ############
    def raise_an_error():
    a = 3
    b = 4
    c = 0
    try:
    a = a/c
    except:
    import sys, cgitb, traceback, inspect
    tbt,tbv,tb = sys.exc_info()
    print
    'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
    print '\n\ncgitb\n',cgitb.text((tbt,tbv,tb),1)

    raise_an_error()
    ############

    @rgbecker rgbecker mannequin closed this as completed May 15, 2004
    @rgbecker rgbecker mannequin assigned akuchling May 15, 2004
    @rgbecker rgbecker mannequin added the stdlib Python modules in the Lib dir label May 15, 2004
    @rgbecker rgbecker mannequin assigned akuchling May 15, 2004
    @rgbecker rgbecker mannequin added the stdlib Python modules in the Lib dir label May 15, 2004
    @rgbecker
    Copy link
    Mannequin Author

    rgbecker mannequin commented Jun 5, 2004

    Logged In: YES
    user_id=6946

    Whoops tabs and all that the above script should look like
    #####start
    def raise_an_error():
    a = 3
    b = 4
    c = 0
    try:
    a = a/c
    except:
    import sys, cgitb, traceback, inspect
    tbt,tbv,tb = sys.exc_info()
    print \
    'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
    print '\n\ncgitb\n',cgitb.text((tbt,tbv,tb),1)

    raise_an_error()
    #####finish

    The same problem occurs with inspect.trace. this code
    #####start
    import inspect
    try:
    raise ValueError
    except:
    print inspect.trace()
    #####finish produces
    [(<frame object at 0x007BFC60>, 'C:\\tmp\\ttt.py', 5, '?',
    [' print inspect.trace()\n'], 0)]

    ie the returned trace doesn't reflect the current traceback,
    but rather the current frame location. This is also fixed by
    the same patch. Still present in 2.4a0. This is a semantic
    issue. The current test_inspect.py insists that the above
    behaviour is correct so it will also need modifying if the
    fix goes in.

    @rgbecker
    Copy link
    Mannequin Author

    rgbecker mannequin commented Jun 5, 2004

    Logged In: YES
    user_id=6946

    python-2.4a0-954364.patch affects inspect.py,
    test_inspect.py fixes this for me in 2.4a0 and 2.3.3, but
    the semantics of inspect.trace changed so that
    test_inspect.py must alter. If inspect.trace() should always
    return something starting at the call of inspect.trace then
    this patch is *WRONG*

    @akuchling
    Copy link
    Member

    Logged In: YES
    user_id=11375

    In the test program, the exception is raised at line 3, but the .trace() call
    says it was at line 5.

    @akuchling
    Copy link
    Member

    Logged In: YES
    user_id=11375

    Alternative version of the patch.

    @akuchling
    Copy link
    Member

    Logged In: YES
    user_id=11375

    Applied to both CVS HEAD and the 2.3 branch. Thanks!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant