[Python-Dev] PEP 460 reboot

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Jan 13 22:02:52 CET 2014

Guido van Rossum wrote:
> On Sun, Jan 12, 2014 at 5:27 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>>On 01/12/2014 04:47 PM, Guido van Rossum wrote:
>>>b'%s' % 'x' == b"'x'" (i.e. the three-byte string containing an 'x'
>>>enclosed in single quotes)
>>I'm not sure about the quotes.  Would anyone ever actually want those in the
>>byte stream?
> Perhaps not, but it's a hint that you should probably think about an
> encoding. It's symmetric with how '%s' % b'x' returns "b'x'". Think of
> it as payback time. :-)

If it's never useful, wouldn't it be better to raise an
exception in this case?

That way, someone porting code from py2 that does this
without appropriate modification will find out about
the problem immediately, rather than have spurious
quotes inserted into their binary data, which -- being
binary data -- will likely go unnoticed until something
else tries to read the data.

I don't think the rule against operations that work on
all-but-one-type really applies here, because the mistake
it's intended to catch is not an obscure corner case.
If your program's logic includes interpolating strings
into bytes objects, then you're going to be testing


More information about the Python-Dev mailing list