[issue1927] raw_input behavior incorrect if readline not enabled

Martin Panter report at bugs.python.org
Sat Nov 21 20:13:22 EST 2015


Martin Panter added the comment:

The input() implementation is a bit like this:

def input(prompt):
    if stdin and stdout are the original file descriptors, and are terminals:
        return PyOS_Readline(sys.stdin, sys.stdout, prompt)
    else:
        sys.stdout.write(prompt)  # Writes to stdout
        return sys.stdin.readline()

def PyOS_StdioReadline(stdin, stdout, prompt):
    '''Default implementation of PyOS_Readline()'''
    sys.stderr.write(prompt)  # Writes to stderr
    return stdin.readline()

def call_readline(stdin, stdout, prompt):
    '''Implementation of PyOS_Readline() in the "readline" module'''
    rl_instream = stdin
    rl_outstream = stdout  # Readline writes to stdout
    return readline_until_enter_or_signal(prompt)

It looks like PyOS_StdioReadline() has always written to stderr. The stdin and stdout parameters of PyOS_Readline() were added later, in revision dc4a0336a2a3.

I think the changes to myreadline.c will also affect the interactive interpreter prompt. But we have Issue 12869 open to change that to stdout, so maybe the change is okay.

Since input() should no longer depend on any instance of stderr, perhaps the check for “lost sys.stderr” should also be removed.

It may be worth applying any changes in myreadline.c to the independent version in pgenmain.c as well, just for consistency.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1927>
_______________________________________


More information about the Python-bugs-list mailing list