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.

Author wiggin15
Recipients wiggin15
Date 2016-10-06.09:13:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1475745183.18.0.209614419228.issue28373@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-10-06 09:13:03wiggin15setrecipients: + wiggin15
2016-10-06 09:13:03wiggin15setmessageid: <1475745183.18.0.209614419228.issue28373@psf.upfronthosting.co.za>
2016-10-06 09:13:03wiggin15linkissue28373 messages
2016-10-06 09:13:02wiggin15create