collections.abc.BytesLike or ...? [was: [Python-Dev] bytes-like objects]
2014-10-05 Victor Stinner <victor.stinner@gmail.com> dixit:
I prefer "bytes-like" than "buffer protocol". By the way, is there a documentation in Python doc which explains "bytes-like" and maybe list most compatible types?
I'm not sure that the term has an unique definition. In some parts of Python, I saw explicit checks on the type: bytes or bytearray, sometimes memoryview is accepted. The behaviour is different in C functions using PyArg API. It probably depends if the function relies on the content (read bytes) or on methods (ex: call .find).
Maybe an ABC would be useful for isinstance checks? Or some kind of almost-an-ABC-which-does-not-allow-to-register- -arbitrary-virtual-subclasses? Cheers. *j
On 06.10.14 01:42, Jan Kaliszewski wrote:
2014-10-05 Victor Stinner <victor.stinner@gmail.com> dixit:
I prefer "bytes-like" than "buffer protocol". By the way, is there a documentation in Python doc which explains "bytes-like" and maybe list most compatible types?
I'm not sure that the term has an unique definition. In some parts of Python, I saw explicit checks on the type: bytes or bytearray, sometimes memoryview is accepted. The behaviour is different in C functions using PyArg API. It probably depends if the function relies on the content (read bytes) or on methods (ex: call .find).
Maybe an ABC would be useful for isinstance checks?
Or some kind of almost-an-ABC-which-does-not-allow-to-register- -arbitrary-virtual-subclasses?
Just use an object in functions which requires bytes-like argument (e.g. memoryview or two-arguments str).
participants (2)
-
Jan Kaliszewski -
Serhiy Storchaka