Author m01
Recipients m01
Date 2018-06-03.12:03:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528027425.26.0.592728768989.issue33749@psf.upfronthosting.co.za>
In-reply-to
Content
It looks like there's possibly a typo/small bug in the pdb.Pdb code. If I supply the stdin argument to the constructor, and provide e.g. a io.StringIO object, then I expect commands to be read from there. This however doesn't happen. If I additionally supply a stdout argument, then it works.

This is because use_rawinput is only disabled if stdout is specified, see https://github.com/python/cpython/blob/3.7/Lib/pdb.py#L144:

...
    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:
            self.use_rawinput = 0
...

I think it should be disabled if stdin is supplied, or possibly if either is specified (I'm not sure).

Repro:

import pdb
import io
pdb_script = io.StringIO("p 'hello';; c")
output = io.StringIO()

Buggy behaviour:

In [5]: pdb.Pdb(stdin=pdb_script).set_trace()
--Call--
> /usr/lib/python3.6/site-packages/IPython/core/displayhook.py(247)__call__()
-> def __call__(self, result=None):
(Pdb) c

Expected behaviour:

(Pdb) 'hello'

Working if stdout is supplied:

In [6]: pdb_script.seek(0)
Out[6]: 0

In [7]: pdb.Pdb(stdin=pdb_script, stdout=output).set_trace()

In [8]: print(output.getvalue())
--Call--
> /usr/lib/python3.6/site-packages/IPython/core/displayhook.py(247)__call__()
-> def __call__(self, result=None):
(Pdb) 'hello'


I would've had a go at fixing this, but even after reading the docs at https://docs.python.org/3/library/cmd.html#cmd.Cmd.use_rawinput it's not entirely obvious to me which combinations of stdin/stdout overrides should be valid and when use_rawinput should be set to 0. However, I'm pretty sure it should at least be set to 0 if stdin is supplied, which currently isn't the case.
History
Date User Action Args
2018-06-03 12:03:45m01setrecipients: + m01
2018-06-03 12:03:45m01setmessageid: <1528027425.26.0.592728768989.issue33749@psf.upfronthosting.co.za>
2018-06-03 12:03:45m01linkissue33749 messages
2018-06-03 12:03:44m01create