[New-bugs-announce] [issue29611] TextIOWrapper's write_through option behave differently between C and pure Python implementation.

INADA Naoki report at bugs.python.org
Tue Feb 21 04:50:54 EST 2017


New submission from INADA Naoki:

In C implementation, write() calls underlaying flush() method when write_through=True.

https://github.com/python/cpython/blob/3.6/Modules/_io/textio.c

    if (self->write_through)
        text_needflush = 1;
    if (self->line_buffering &&
        (haslf ||
         PyUnicode_FindChar(text, '\r', 0, PyUnicode_GET_LENGTH(text), 1) != -1))
        needflush = 1;


But pure Python implementation doesn't care write_through option at all.

https://github.com/python/cpython/blob/3.6/Lib/_pyio.py

        self.buffer.write(b)
        if self._line_buffering and (haslf or "\r" in s):
            self.flush()

When PyPy 3.5 is released, this difference may affects PyPy users.
(I hadn't checked how PyPy provide io module.)

----------
components: IO
messages: 288282
nosy: inada.naoki
priority: normal
severity: normal
status: open
title: TextIOWrapper's write_through option behave differently between C and pure Python implementation.
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7

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


More information about the New-bugs-announce mailing list