This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: pdb's debug command (Pdb.do_debug) doesn't use rawinput even if the parent pdb uses rawinput
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Segev Finer, blueyed
Priority: normal Keywords:

Created on 2017-07-29 21:02 by Segev Finer, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 2947 open Segev Finer, 2017-07-29 21:07
Messages (5)
msg299485 - (view) Author: Segev Finer (Segev Finer) * Date: 2017-07-29 21:02
This is caused by which always passes our own current stdin and stdout, and this triggers the conditional in

self.stdin and self.stdout are initialized to sys.stdin and sys.stdout respectively when not passed explicitly:

See Also:
msg336770 - (view) Author: daniel hahler (blueyed) * Date: 2019-02-27 17:01
I can confirm that this fixes cursor keys not working properly after "debug foo()" (recursive debugging) with pdb.
msg342634 - (view) Author: daniel hahler (blueyed) * Date: 2019-05-16 10:11
It was added in 477c8d5e702 (a huge svn merge commit), with this reference:

      r45955 | georg.brandl | 2006-05-10 19:13:20 +0200 (Wed, 10 May 2006) | 4 lines

      Patch #721464: pdb.Pdb instances can now be given explicit stdin and
      stdout arguments, making it possible to redirect input and output
      for remote debugging.

I think a good alternative patch might be:

 Lib/ | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git i/Lib/ w/Lib/
index f5d33c27fc..daf49b3629 100755
--- i/Lib/
+++ w/Lib/
@@ -141,7 +141,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
                  nosigint=False, readrc=True):
         bdb.Bdb.__init__(self, skip=skip)
         cmd.Cmd.__init__(self, completekey, stdin, stdout)
-        if stdout:
+        if stdout and stdout is not sys.stdout:
+            # stdout gets passed with do_debug for example, but should usually
+            # not disable using raw input then.
             self.use_rawinput = 0
         self.prompt = '(Pdb) '
         self.aliases = {}
msg342635 - (view) Author: daniel hahler (blueyed) * Date: 2019-05-16 10:12
Just for reference and searchability: this causes tab completion to not work with `debug foo()` also.
msg342637 - (view) Author: daniel hahler (blueyed) * Date: 2019-05-16 10:35
> I think a good alternative patch might be:

This however makes it behave different in tests, where stdout might be mocked/wrapped intentionally.

Therefore I think using the parent's `use_rawinput` is the better fix for this (the originally proposed patch).
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75261
2019-05-16 10:35:56blueyedsetmessages: + msg342637
2019-05-16 10:12:55blueyedsetmessages: + msg342635
2019-05-16 10:11:02blueyedsetmessages: + msg342634
versions: + Python 3.9
2019-02-27 17:01:35blueyedsetnosy: + blueyed

messages: + msg336770
versions: + Python 3.8
2017-07-29 21:07:50Segev Finersetpull_requests: + pull_request2996
2017-07-29 21:02:07Segev Finercreate