New submission from Arnon Yaari:

When I wrap sys.stdout with a custom object that overrides the 'write' method, 
regular prints use the custom write method, but the input() function prints the 
prompt to the original stdout.
This is broken on Python 3.5. Earlier versions work correctly.
In the following example 'write' does nothing, so I expect no output, but the 
input() function outputs to stdout anyway:

import sys

class StreamWrapper(object):
    def __init__(self, wrapped):
        self.__wrapped = wrapped

    def __getattr__(self, name):
        # 'write' is overridden but for every other function, like 'flush', use 
the original wrapped stream
        return getattr(self.__wrapped, name)

    def write(self, text):
        pass

orig_stdout = sys.stdout
sys.stdout = StreamWrapper(orig_stdout)
print('a')   # this prints nothing
input('b')   # this should print nothing, but prints 'b' (in Python 3.5 and up 
only)

Looks like this was broken in http://bugs.python.org/issue24402 . Adding the 
'fileno' function from this issue fixes the problem, but it's just a 
workaround. This affects the colorama package: 
https://github.com/tartley/colorama/issues/103

----------
messages: 278179
nosy: wiggin15
priority: normal
severity: normal
status: open
title: input() prints to original stdout even if sys.stdout is wrapped
versions: Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28373>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to