https://github.com/python/cpython/commit/bc9b9d47f9d649661c9c0c3e042ad9e559b9c81e
commit: bc9b9d47f9d649661c9c0c3e042ad9e559b9c81e
branch: main
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2025-11-19T18:41:25-08:00
summary:

gh-141615: Check stdin instead of stdout for use_rawinput in pdb (#141616)

files:
A Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst
M Lib/pdb.py
M Lib/test/test_pdb.py

diff --git a/Lib/pdb.py b/Lib/pdb.py
index 76bb28d7396452..8e9502cb9e6bfb 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -346,8 +346,8 @@ def __init__(self, completekey='tab', stdin=None, 
stdout=None, skip=None,
         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 = {}
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 9d89008756a1d3..418ea79cdd22c3 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -4744,6 +4744,19 @@ def test_readline_not_imported(self):
         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
index 00000000000000..bb54e68398722f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst
@@ -0,0 +1 @@
+Check ``stdin`` instead of ``stdout`` for ``use_rawinput`` in :mod:`pdb`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to