]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141615: Check stdin instead of stdout for use_rawinput in pdb (#141616)
authorTian Gao <gaogaotiantian@hotmail.com>
Thu, 20 Nov 2025 02:41:25 +0000 (18:41 -0800)
committerGitHub <noreply@github.com>
Thu, 20 Nov 2025 02:41:25 +0000 (18:41 -0800)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst [new file with mode: 0644]

index 76bb28d739645252ff4b070bffb444d4372ffb64..8e9502cb9e6bfb76b3bdd7395ec34df421c0aa16 100644 (file)
@@ -346,8 +346,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         bdb.Bdb.__init__(self, skip=skip, backend=backend if backend else get_default_backend())
         cmd.Cmd.__init__(self, completekey, stdin, stdout)
         sys.audit("pdb.Pdb")
-        if stdout:
-            self.use_rawinput = 0
+        if stdin:
+            self.use_rawinput = False
         self.prompt = '(Pdb) '
         self.aliases = {}
         self.displaying = {}
index 9d89008756a1d33798bcc7911e774735463183e6..418ea79cdd22c37d1cc36c96968eff194f2a1571 100644 (file)
@@ -4744,6 +4744,19 @@ class PdbTestInline(unittest.TestCase):
         self.assertNotIn("readline imported", stdout)
         self.assertEqual(stderr, "")
 
+    def test_alternate_stdin(self):
+        script = textwrap.dedent("""
+            import pdb
+            import io
+
+            input_data = io.StringIO("p 40 + 2\\nc\\n")
+            pdb.Pdb(stdin=input_data).set_trace()
+        """)
+        commands = ""
+        stdout, stderr = self._run_script(script, commands)
+        self.assertIn("42", stdout)
+        self.assertEqual(stderr, "")
+
 
 @support.force_colorized_test_class
 class PdbTestColorize(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst b/Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst
new file mode 100644 (file)
index 0000000..bb54e68
--- /dev/null
@@ -0,0 +1 @@
+Check ``stdin`` instead of ``stdout`` for ``use_rawinput`` in :mod:`pdb`.