diff --git a/Lib/pdb.py b/Lib/pdb.py index b799a113503502..2a168252f9f326 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 9a7d855003551a..b8ede93d7b4e0d 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4710,6 +4710,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`.