]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124703: Change back to raising bdb.BdbQuit when exiting pdb in 'inline' mode in...
authorAdam D. Thomas <adamthomas17@gmail.com>
Tue, 25 Feb 2025 02:27:26 +0000 (13:27 +1100)
committerGitHub <noreply@github.com>
Tue, 25 Feb 2025 02:27:26 +0000 (21:27 -0500)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2025-02-21-09-05-44.gh-issue-124703.AMJD4Y.rst [new file with mode: 0644]

index 08a941de79ec55d290c48bfc2b77ee35d963bebd..ea6a7890f8c2bc68854a08b4d86d239510ba84c9 100644 (file)
@@ -1758,7 +1758,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
 
         Quit from the debugger. The program being executed is aborted.
         """
-        if self.mode == 'inline':
+        # Show prompt to kill process when in 'inline' mode and if pdb was not
+        # started from an interactive console. The attribute sys.ps1 is only
+        # defined if the interpreter is in interactive mode.
+        if self.mode == 'inline' and not hasattr(sys, 'ps1'):
             while True:
                 try:
                     reply = input('Quitting pdb will kill the process. Quit anyway? [y/n] ')
index 83753279599f76db84ca65ec19ecbdf6a41d6753..7a99c1db84b4397e33f4cdfd0ec3c098869ecb0c 100644 (file)
@@ -19,6 +19,7 @@ from test import support
 from test.support import force_not_colorized, os_helper
 from test.support.import_helper import import_module
 from test.support.pty_helper import run_pty, FakeInput
+from test.support.script_helper import kill_python
 from unittest.mock import patch
 
 SKIP_CORO_TESTS = False
@@ -4342,6 +4343,29 @@ class PdbTestInline(unittest.TestCase):
         self.assertEqual(stdout.count("Quit anyway"), 2)
 
 
+@support.force_not_colorized_test_class
+@support.requires_subprocess()
+class TestREPLSession(unittest.TestCase):
+    def test_return_from_inline_mode_to_REPL(self):
+        # GH-124703: Raise BdbQuit when exiting pdb in REPL session.
+        # This allows the REPL session to continue.
+        from test.test_repl import spawn_repl
+        p = spawn_repl()
+        user_input = """
+            x = 'Spam'
+            import pdb
+            pdb.set_trace(commands=['x + "During"', 'q'])
+            x + 'After'
+        """
+        p.stdin.write(textwrap.dedent(user_input))
+        output = kill_python(p)
+        self.assertIn('SpamDuring', output)
+        self.assertNotIn("Quit anyway", output)
+        self.assertIn('BdbQuit', output)
+        self.assertIn('SpamAfter', output)
+        self.assertEqual(p.returncode, 0)
+
+
 @support.requires_subprocess()
 class PdbTestReadline(unittest.TestCase):
     def setUpClass():
diff --git a/Misc/NEWS.d/next/Library/2025-02-21-09-05-44.gh-issue-124703.AMJD4Y.rst b/Misc/NEWS.d/next/Library/2025-02-21-09-05-44.gh-issue-124703.AMJD4Y.rst
new file mode 100644 (file)
index 0000000..0ec9145
--- /dev/null
@@ -0,0 +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`.