[Python-ideas] collections.abc.BytesLike or ...? [was: [Python-Dev] bytes-like objects]

Serhiy Storchaka storchaka at gmail.com
Mon Oct 6 14:30:33 CEST 2014


On 06.10.14 01:42, Jan Kaliszewski wrote:
> 2014-10-05 Victor Stinner <victor.stinner at 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).




More information about the Python-ideas mailing list