[issue20699] Document that binary IO classes work with bytes-likes objects

Martin Panter report at bugs.python.org
Fri Jun 3 05:59:13 EDT 2016


Martin Panter added the comment:

I don’t see the point of mentioning array() objects at all. It’s hard to support array in a Python 2 implementation, as demonstrated by readinto(). And the special support for array('b') won’t help if you pass in array('B') with values 128–255. I see this as an implementation detail of _pyio, rather than a need for others to follow its lead.

The array('b') code was added by r56225. I guess it is experimental code from an early phase of the io module. Also, test_array_writes() is disabled for _pyio in 2.7 (https://hg.python.org/cpython/diff/760a710eb6c1/Lib/test/test_io.py), and in 2.6 (http://svn.python.org/view/python/branches/trunk-bytearray/Lib/test/test_io.py?r1=61775&r2=61774&pathrev=61775&view=patch).

I think it is better to avoid “such as” and be specific about what has to be supported. Perhaps:

readinto(b): The object *b* should be a pre-allocated, writable array of bytes, either :class:`bytearray` or :class:`memoryview`.

.. versionchanged:: 2.7
   Support for :class:`memoryview`.

write(b): The object *b* should be an array of bytes, either :class:`str`, :class:`bytearray`, or :class:`memoryview`.

.. versionchanged:: 2.7
   Support for :class:`memoryview`.

----------

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


More information about the Python-bugs-list mailing list