https://github.com/python/cpython/commit/e66597d6c84a8615340822b8da564e5ca3fba5cd
commit: e66597d6c84a8615340822b8da564e5ca3fba5cd
branch: main
author: Yongtao Huang <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2026-01-19T16:11:07-08:00
summary:
gh-143874: Use self.message instead of raw print in `_exec_in_closure()`
(#143875)
files:
A Misc/NEWS.d/next/Library/2026-01-15-16-04-39.gh-issue-143874.1qQgvo.rst
M Lib/pdb.py
M Lib/test/test_remote_pdb.py
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 0464b288ef825a..b5d8f827827415 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -888,7 +888,7 @@ def _exec_in_closure(self, source, globals, locals):
locals.update(pdb_eval["write_back"])
eval_result = pdb_eval["result"]
if eval_result is not None:
- print(repr(eval_result))
+ self.message(repr(eval_result))
return True
diff --git a/Lib/test/test_remote_pdb.py b/Lib/test/test_remote_pdb.py
index ede99de981971a..d26d63faa61ddb 100644
--- a/Lib/test/test_remote_pdb.py
+++ b/Lib/test/test_remote_pdb.py
@@ -1441,6 +1441,34 @@ def test_multi_line_commands(self):
self.assertIn("Function returned: 42", stdout)
self.assertEqual(process.returncode, 0)
+ def test_exec_in_closure_result_uses_pdb_stdout(self):
+ """
+ Expression results executed via _exec_in_closure() should be written
+ to the debugger output stream (pdb stdout), not to sys.stdout.
+ """
+ self._create_script()
+ process, client_file = self._connect_and_get_client_file()
+
+ with kill_on_error(process):
+ self._read_until_prompt(client_file)
+
+ self._send_command(client_file, "(lambda: 123)()")
+ messages = self._read_until_prompt(client_file)
+ result_msg = "".join(msg.get("message", "") for msg in messages)
+ self.assertIn("123", result_msg)
+
+ self._send_command(client_file, "sum(i for i in (1, 2, 3))")
+ messages = self._read_until_prompt(client_file)
+ result_msg = "".join(msg.get("message", "") for msg in messages)
+ self.assertIn("6", result_msg)
+
+ self._send_command(client_file, "c")
+ stdout, _ = process.communicate(timeout=SHORT_TIMEOUT)
+
+ self.assertNotIn("\n123\n", stdout)
+ self.assertNotIn("\n6\n", stdout)
+ self.assertEqual(process.returncode, 0)
+
def _supports_remote_attaching():
PROCESS_VM_READV_SUPPORTED = False
diff --git
a/Misc/NEWS.d/next/Library/2026-01-15-16-04-39.gh-issue-143874.1qQgvo.rst
b/Misc/NEWS.d/next/Library/2026-01-15-16-04-39.gh-issue-143874.1qQgvo.rst
new file mode 100644
index 00000000000000..a11cf715b04a8d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-01-15-16-04-39.gh-issue-143874.1qQgvo.rst
@@ -0,0 +1 @@
+Fixed a bug in :mod:`pdb` where expression results were not sent back to
remote client.
_______________________________________________
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]