2014/1/11 Ethan Furman <et...@stoneleaf.us>:
>>> b'x=%s' % 10 is well defined, it's pure bytes.
>>
>> It is well-defined? Then please explain me what the general case of
>>    b'%s' % x
>> is supposed to call:
>
> This is the key question, isn't it?

Python 2 and Python 3 are very different here.

In Python 2, the "s" format of PyArg_Parse may call the __str__()
method of an object.

In Python 3, the "y*" format of PyArg_Parse uses the Py_buffer API
which has no slot (there is no protocol like a __getbuffer__()
method).  The Py_buffer can only be implemented in C. For example,
bytes, bytearray and memoryview implement it. PyArg_Parse requires
also the buffer to be C-contiguous and has a single segment (use
PyBUF_SIMPLE flag).

Said differently, bytes%args and bytes.format() would *not* call any method.

Victor
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to