Skip to content

Commit acec24a

Browse files
ADThomas-astroseehwan80
authored andcommitted
pythongh-124703: Change back to raising bdb.BdbQuit when exiting pdb in 'inline' mode in a REPL session (python#130395)
1 parent fefd66f commit acec24a

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Lib/pdb.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,10 @@ def do_quit(self, arg):
17581758
17591759
Quit from the debugger. The program being executed is aborted.
17601760
"""
1761-
if self.mode == 'inline':
1761+
# Show prompt to kill process when in 'inline' mode and if pdb was not
1762+
# started from an interactive console. The attribute sys.ps1 is only
1763+
# defined if the interpreter is in interactive mode.
1764+
if self.mode == 'inline' and not hasattr(sys, 'ps1'):
17621765
while True:
17631766
try:
17641767
reply = input('Quitting pdb will kill the process. Quit anyway? [y/n] ')

Lib/test/test_pdb.py

+24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from test.support import force_not_colorized, os_helper
2020
from test.support.import_helper import import_module
2121
from test.support.pty_helper import run_pty, FakeInput
22+
from test.support.script_helper import kill_python
2223
from unittest.mock import patch
2324

2425
SKIP_CORO_TESTS = False
@@ -4342,6 +4343,29 @@ def test_quit(self):
43424343
self.assertEqual(stdout.count("Quit anyway"), 2)
43434344

43444345

4346+
@support.force_not_colorized_test_class
4347+
@support.requires_subprocess()
4348+
class TestREPLSession(unittest.TestCase):
4349+
def test_return_from_inline_mode_to_REPL(self):
4350+
# GH-124703: Raise BdbQuit when exiting pdb in REPL session.
4351+
# This allows the REPL session to continue.
4352+
from test.test_repl import spawn_repl
4353+
p = spawn_repl()
4354+
user_input = """
4355+
x = 'Spam'
4356+
import pdb
4357+
pdb.set_trace(commands=['x + "During"', 'q'])
4358+
x + 'After'
4359+
"""
4360+
p.stdin.write(textwrap.dedent(user_input))
4361+
output = kill_python(p)
4362+
self.assertIn('SpamDuring', output)
4363+
self.assertNotIn("Quit anyway", output)
4364+
self.assertIn('BdbQuit', output)
4365+
self.assertIn('SpamAfter', output)
4366+
self.assertEqual(p.returncode, 0)
4367+
4368+
43454369
@support.requires_subprocess()
43464370
class PdbTestReadline(unittest.TestCase):
43474371
def setUpClass():
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
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`.

0 commit comments

Comments
 (0)