[issue21057] TextIOWrapper does not support reading bytearrays or memoryviews

Nikolaus Rath report at bugs.python.org
Tue Mar 25 05:14:29 CET 2014


New submission from Nikolaus Rath:

In Python 3.4, TextIOWrapper can not read from streams that return bytearrays or memoryviews:

from io import TextIOWrapper, BytesIO
class MyByteStream(BytesIO):
    def read1(self, len_):
        return memoryview(super().read(len_))
bs = MyByteStream(b'some data in ascii\n')
ss = TextIOWrapper(bs, encoding='ascii')
print(ss.read(200))

results in:

TypeError: underlying read1() should have returned a bytes object, not 'memoryview'

I don't think there's any good reason for TextIOWrapper not accepting any bytes-like object (especially now that b''.join finally accepts bytes-like objects as well).

----------
components: Library (Lib)
messages: 214776
nosy: nikratio
priority: normal
severity: normal
status: open
title: TextIOWrapper does not support reading bytearrays or memoryviews
type: behavior
versions: Python 3.5

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


More information about the Python-bugs-list mailing list