Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ def onecmd(self, line):
if cmd == '':
return self.default(line)
else:
try:
func = getattr(self, 'do_' + cmd)
except AttributeError:
return self.default(line)
return func(arg)
func = getattr(self, 'do_' + cmd, None)
if func is not None:
return func(arg)
return self.default(line)
Comment on lines +213 to +216

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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)

Copy link
Copy Markdown
Member

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)

Copy link
Copy Markdown
Member

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.


def emptyline(self):
"""Called when an empty line is entered in response to the prompt.
Expand Down
5 changes: 1 addition & 4 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,7 @@ def handle_command_def(self, line):
else:
cmdlist.append(cmd)
# Determine if we must stop
try:
func = getattr(self, 'do_' + cmd)
except AttributeError:
func = self.default
func = getattr(self, 'do_' + cmd, self.default)
# one of the resuming commands
if func.__name__ in self.commands_resuming:
self.commands_doprompt[self.commands_bnum] = False
Expand Down