The Wayback Machine - https://web.archive.org/web/20250612115757/https://github.com/python/cpython/pull/4666
Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Dec 1, 2017

This allows for sys.exc_info being more useful, when it is not
swallowed 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

This allows for `sys.exc_info` being more useful, when it is not
swallowed by an (unnecessary) `AttributeError` in pdb itself.
@blueyed blueyed changed the title pdb/cmd: avoid creating exceptions bpo-36550: pdb/cmd: avoid creating exceptions Apr 7, 2019
Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

news?

@blueyed
Copy link
Contributor Author

blueyed commented Jun 3, 2019

news?

When it gets accepted finally. As mentioned before, there are likely more places - this is rather old already.

@iritkatriel
Copy link
Member

@blueyed I agree with this. Are you still interested in working on it?

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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?

Comment on lines +213 to +216
func = getattr(self, 'do_' + cmd, None)
if func is not None:
return func(arg)
return self.default(line)
Copy link
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
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
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
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.

@iritkatriel
Copy link
Member

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.

@iritkatriel iritkatriel closed this Sep 7, 2021
@blueyed
Copy link
Contributor Author

blueyed commented Sep 7, 2021

See https://bugs.python.org/msg401253 for more info / a response.
I've created the issue for discussion / the reasoning in the first place - sorry for not having responded here earlier.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Aug 13, 2022
@ghost
Copy link

ghost commented Feb 26, 2023

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Feb 27, 2023
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Mar 29, 2023
Copy link

@auvipy auvipy left a 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

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Mar 30, 2023
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 30, 2023
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label May 1, 2023
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label May 31, 2023
@serhiy-storchaka
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants