[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3

Ethan Furman ethan at stoneleaf.us
Tue Sep 16 17:04:37 CEST 2014


On 09/16/2014 06:02 AM, Eric V. Smith wrote:
> On 09/15/2014 08:43 PM, Ethan Furman wrote:
>> On 09/15/2014 04:47 PM, Nick Coghlan wrote:
>>>
>>> The current suggestion on the issue tracker is to add __format__ to
>>> bytes/bytearray/memoryview with a suitable symbolic mini-language to
>>>   control the formatting details.
>>
>> PEP 461 specifically did not add back __format__ to bytes/bytearrays.  I
>> think a PEP is appropriate to reverse that decision.
>
> That's different. PEP 461 excluded them because it was talking about
> bytes.format(). bytes.__format__() would be much easier to deal with,
> because its result must be unicode (str in 3.x).
>
> I don't think just adding bytes/bytearray.__format__() per se requires a
> PEP. It's not a very radical addition, similar to datetime.__format__().
> But I wouldn't be opposed to a PEP to decide on the specifics of the
> mini-language that bytes.__format__() supports.

So the difference is:

    b'Hello, %s' % some_bytes_var --> b'Hello, <whatever>'

whilst

    b'Hello, {}'.format(some_uni_var) --> u'Hello, <whatever>'

(Yes, I remember unicode == str, I was just being explicit ;)

That would certainly go along with the idea that `format` is for strings.

--
~Ethan~


More information about the Python-ideas mailing list