bpo-34989: python-gdb.py: fix current_line_num() by vstinner · Pull Request #9889 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

vstinner

python-gdb.py now handles errors on computing the line number
of a Python frame.

Changes:

https://bugs.python.org/issue34989

@vstinner

python-gdb.py now handles errors on computing the line number of a Python frame.

Changes:

ambv

ambv approved these changes Oct 15, 2018

Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

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

This is great and fixes a problem I've seen in the past. I left a nit and two questions for your consideration, Victor.

lineno = self.current_line_num()
if lineno is None:
return '(failed to get frame line number)'

Choose a reason for hiding this comment

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

tiny nit: that could also have a blank line after to make it obvious you're returning early.

Choose a reason for hiding this comment

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

I concur, done.

try:
f = open(os_fsencode(filename), 'r')
with open(os_fsencode(filename), 'r') as fp:
lines = fp.readlines()
except IOError:
return None

Choose a reason for hiding this comment

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

Could we maybe return '(failed to read source)' instead of "None" here? That would maybe be more descriptive, what do you think?

Choose a reason for hiding this comment

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

This code mimicks linecache.getline() which is used to render a traceback.

Choose a reason for hiding this comment

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

To be honest, I was also surprised at the first read, and I had to double check when I saw your comment :-D

# Convert from 1-based current_line_num to 0-based list offset
return lines[lineno - 1]
except IndexError:
return None

Choose a reason for hiding this comment

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

Same here. If we have an index error that means the file did not match. Maybe we should say this to the user?

Choose a reason for hiding this comment

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

Ditto, linecache.getline() behaves the same, and the code mimicks linecache's behaviour.

@vstinner

@miss-islington

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Oct 15, 2018

@vstinner @miss-islington

python-gdb.py now handles errors on computing the line number of a Python frame.

Changes:

Co-authored-by: Victor Stinner vstinner@redhat.com

@bedevere-bot

@miss-islington

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Oct 15, 2018

@vstinner @miss-islington

python-gdb.py now handles errors on computing the line number of a Python frame.

Changes:

Co-authored-by: Victor Stinner vstinner@redhat.com

@bedevere-bot

miss-islington added a commit that referenced this pull request

Oct 15, 2018

@miss-islington @vstinner

python-gdb.py now handles errors on computing the line number of a Python frame.

Changes:

Co-authored-by: Victor Stinner vstinner@redhat.com

miss-islington added a commit that referenced this pull request

Oct 15, 2018

@miss-islington @vstinner

python-gdb.py now handles errors on computing the line number of a Python frame.

Changes:

Co-authored-by: Victor Stinner vstinner@redhat.com

vstinner added a commit that referenced this pull request

Oct 15, 2018

@vstinner

python-gdb.py now handles errors on computing the line number of a Python frame.

Changes:

(cherry picked from commit 2e438cc)

@vstinner

Thanks Łukasz Langa @ambv fo the review!

vstinner added a commit that referenced this pull request

Oct 16, 2018

@vstinner

CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request

Oct 18, 2018

@CuriousLearner

CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request

Oct 18, 2018

@CuriousLearner