-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-36550: pdb/cmd: avoid creating exceptions #4666
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
Conversation
This allows for `sys.exc_info` being more useful, when it is not swallowed by an (unnecessary) `AttributeError` in pdb itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
news?
When it gets accepted finally. As mentioned before, there are likely more places - this is rather old already. |
@blueyed I agree with this. Are you still interested in working on it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can any tests be added?
func = getattr(self, 'do_' + cmd, None) | ||
if func is not None: | ||
return func(arg) | ||
return self.default(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work too?
try:
func = getattr(self, 'do_' + cmd)
except AttributeError:
pass # restore the original sys.exc_info()
else:
return func(arg)
return self.default(line)
I do not suggest this code, just ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it works if you add a naked raise at the end of the except block. Try this:
try:
raise ValueError(1)
except:
try:
raise AttributeError(2)
except AttributeError:
pass
else:
print(42)
raise
else:
print(53)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In something like pdb you would need to check if there is an active exception. Something like this:
import sys
def maybe_reraise():
if sys.exc_info() != (None, None, None):
raise
try:
raise ValueError(1)
except:
try:
raise AttributeError(2)
except AttributeError:
pass
else:
print(42)
maybe_reraise()
else:
print(53)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed the point - we don't want to raise the exception, just to restore it. In that case doesn't my example show that there is no issue?
I'm not sure this PR is needed after all. If we had a test we would know, but since @blueyed is no longer responding we may need to just close it until an actual bug is reported.
Closing as the bug is not clear and the OP is not responding to requests to clarify it. Please create a new issue if you are still seeing a problem. |
See https://bugs.python.org/msg401253 for more info / a response. |
This PR is stale because it has been open for 30 days with no activity. |
The following commit authors need to sign the Contributor License Agreement: |
This PR is stale because it has been open for 30 days with no activity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if appropriate test is provided, it would be easier to understand if the proposed change is still needed or not
This PR is stale because it has been open for 30 days with no activity. |
This PR is stale because it has been open for 30 days with no activity. |
The original issue was fixed in #111740 which applied the same change in Lib/cmd.py. The change in Lib/pdb.py looks not necessary. |
This allows for
sys.exc_info
being more useful, when it is notswallowed by an (unnecessary)
AttributeError
in pdb itself.There might be more places, but I had this local changes and wanted to ask for feedback on it already.
https://bugs.python.org/issue36550