[issue20699] Document that binary IO classes work with bytes-likes objects
R. David Murray added the comment: What is your objection to "len(b)"? When I read "len(b)" I know exactly what it means. When I read "the number of bytes in b", I have to think about it it, because it could mean "the number of bytes that that b is long" or "the number of bytes that have been already written to b", and the latter is the meaning my mind goes to first, so it takes time for my mind to realize it is the first. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20699> _______________________________________
Serhiy Storchaka added the comment: Because it is not len(b). I fixed several bugs in Python code which called len() for bytes-like argument and failed with array.array or memoryview with non-byte items. The term "bytes-like object" is slightly misleading. In some cases it implies indexing and len, and iterating, and may be slicing -- common operations for bytes, bytearray, array('B'), memoryview().cast('B'). In more narrow meaning it may require such operations as concatenation (operator +) and .startswith() -- common for bytes and bytearray. In more general meaning it requires only the support of buffer protocol and contiguity. In more general meaning it may be even non-contiguous. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20699> _______________________________________
participants (2)
-
R. David Murray
-
Serhiy Storchaka