bpo-36550: pdb/cmd: avoid creating exceptions#4666
bpo-36550: pdb/cmd: avoid creating exceptions#4666blueyed wants to merge 3 commits intopython:mainfrom
Conversation
This allows for `sys.exc_info` being more useful, when it is not swallowed by an (unnecessary) `AttributeError` in pdb itself.
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? |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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. |
auvipy
left a comment
There was a problem hiding this comment.
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_infobeing more useful, when it is notswallowed by an (unnecessary)
AttributeErrorin 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