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

implement tb_lineno of Traceback #1079

Merged
merged 1 commit into from
Jan 29, 2016
Merged

implement tb_lineno of Traceback #1079

merged 1 commit into from
Jan 29, 2016

Conversation

corona10
Copy link

I implements tb_lineno but I don't know this is right implementatation.
I know tb_linno should assigend by frame's f_lineno but this implementation looks different.
I check it print right tb_lineno on below code after this patch...

import sys, traceback

def lumberjack():
    bright_side_of_death()

def bright_side_of_death():
    return tuple()[0]

try:
    lumberjack()
except IndexError:
    exc_type, exc_value, exc_traceback = sys.exc_info()
    print "*** print_tb:"
    traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
    print "*** print_exception:"
    traceback.print_exception(exc_type, exc_value, exc_traceback,
                              limit=2, file=sys.stdout)
    print "*** print_exc:"
    traceback.print_exc()
    print "*** format_exc, first and last line:"
    formatted_lines = traceback.format_exc().splitlines()
    print formatted_lines[0]
    print formatted_lines[-1]
    print "*** format_exception:"
    print repr(traceback.format_exception(exc_type, exc_value,
                                          exc_traceback))
    print "*** extract_tb:"
    print repr(traceback.extract_tb(exc_traceback))
    print "*** format_tb:"
    print repr(traceback.format_tb(exc_traceback))
    print "*** tb_lineno:", exc_traceback.tb_lineno

@undingen
Copy link
Contributor

Your patch looks good but I would prefer if you would add a test.
#1031 implements the same attribute + some additional stuff but because it may take some more time until this PR lands I'm fine with merging this one in between and rebasing mine.
But I definitely recommending to not but more effort into the traceback and frame object until #1031 landed. (I think after #1031 is merged we can even easily switch to the cpython traceback implementation)

@corona10
Copy link
Author

@undingen Thanks, I added test. But I don't know it will be good or not to be merged mine if you 're already make patch for this. 😄

@@ -145,7 +145,8 @@ void setupTraceback() {
NULL));
*/
traceback_cls->giveAttrDescriptor("tb_next", traceback_tb_next, NULL);

traceback_cls->giveAttr("tb_lineno",
new BoxedMemberDescriptor(BoxedMemberDescriptor::INT, offsetof(BoxedTraceback, tb_lineno)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably do offsetof(BoxedTraceback, line) + offsetof(LineInfo, line) instead of storing the attribute twice.

@corona10
Copy link
Author

@kmod Thanks That's reasonable.

undingen added a commit that referenced this pull request Jan 29, 2016
implement tb_lineno of Traceback
@undingen undingen merged commit 3d4463b into pyston:master Jan 29, 2016
@undingen
Copy link
Contributor

Thanks for the change! 👍

@corona10 corona10 deleted the traceback branch January 29, 2016 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants