On 01/11/2014 10:32 AM, Antoine Pitrou wrote:
On Sat, 11 Jan 2014 18:41:49 +0100
Victor Stinner <victor.stin...@gmail.com> wrote:

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?


- does it call x.__bytes__? int.__bytes__ doesn't exist

Perhaps that's the problem.  According to the docs:
========================================================================
 object.__bytes__(self)

    Called by bytes() to compute a byte-string representation of an object. 
This should return a bytes object.
========================================================================

Obviously, with the plethora of different binary possibilities for representing a number (how many bytes? endianness? which complement?), we would be well within our rights to decide that the "byte-string representation" of the numeric types is the ASCII equivalent of their __repr__ or __str__, and implement __bytes__ appropriately for them. Any other object that wants to be represented easily in a byte stream would also have to implement __bytes__. If necessary we could add __bytes__ to str for /strict/ ASCII conversion (even latin-1 would have to be explicitly encoded)[1].

--
~Ethan~

[1] I'm iffy on this point as I'm not at all sure it's needed.
_______________________________________________
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