Skip to content
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

gh-124703: Change back to raising bdb.BdbQuit when exiting pdb in 'inline' mode in a REPL session #130395

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ADThomas-astro
Copy link

@ADThomas-astro ADThomas-astro commented Feb 21, 2025

This change should mean it's again possible to call breakpoint() in a REPL session and return to the REPL session with q/quit/exit/EOF.

The test has a slight workaround/hack because I couldn't figure out how to call breakpoint() and simulate using pdb interactively within a simulated REPL session in a subprocess. After set_trace() was called, pdb would receive an EOF and exit before it could receive further commands.

If there's interest, I could also add the code from PR129768 to shorten the BdbQuit traceback by one frame.

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@@ -1758,7 +1758,8 @@ def do_quit(self, arg):
Quit from the debugger. The program being executed is aborted.
"""
if self.mode == 'inline':
in_repl_session = hasattr(sys, 'ps1')
Copy link
Member

Choose a reason for hiding this comment

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

I understand that you do not want a magic hasattr(sys, 'ps1') here, but I think it's better to add some comments here about why we do it, instead of trying to use a variable with some explanation. This variable is only used once, in the next immediate line, and it's not even shorter than the actual statement.

@support.requires_subprocess()
class TestREPLSession(unittest.TestCase):
def test_return_from_inline_mode_to_REPL(self):
# Issue #124703: Raise BdbQuit when exiting pdb in REPL session.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Issue #124703: Raise BdbQuit when exiting pdb in REPL session.
# GH-124703: Raise BdbQuit when exiting pdb in REPL session.

pdb.set_trace(commands=['x * 3', 'q'])
print('Afterward')
"""
p = spawn_repl()
Copy link
Member

Choose a reason for hiding this comment

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

Can we import the spawn_repl from test_repl here? So we don't need to keep a copy.

@@ -0,0 +1 @@
Restore the ability to easily return to the REPL from a pdb session after calling ``breakpoint`` or ``set_trace``.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Restore the ability to easily return to the REPL from a pdb session after calling ``breakpoint`` or ``set_trace``.
Executing ``quit`` command in :mod:`pdb` will raise :exc:`bdb.BdbQuit` when :mod:`pdb` is started from an interactive console using :func:`breakpoint` or :func:`pdb.set_trace`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants