[Python-Dev] PEP 460: allowing %d and %f and mojibake

Kristján Valur Jónsson kristjan at ccpgames.com
Sun Jan 12 22:37:05 CET 2014


Right. 
I'm saying, let's support two interpolators only:
%b interpolates a bytes object (or one supporting the charbuffer interface) into a bytes object.
%s interpolates a str object by first converting to a bytes object using strict ascii conversion.

This makes it very explicit what we are trying to do. I think that using %s to interpolate a bytes object like the current PEP does is a bad idea, because %s already means 'str' elsewhere in the language, both in 2.7 and 3.x

As for the case you mention:
b"abc %s" % (b"def",) -> b"abc def"
b"abc %s" % (b"def",) -> b"abc b\"def\""  # because str(bytesobject) == repr(bytesobject)

This is perfectly fine, imho.  Let's not overload %s to mean "bytes" in format strings if those format strnings are in fact not strings byt bytes. That way madness lies.

K
________________________________________
From: Paul Moore [p.f.moore at gmail.com]
Sent: Sunday, January 12, 2014 17:04
To: Kristján Valur Jónsson
Cc: Nick Coghlan; Georg Brandl; python-dev at python.org
Subject: Re: [Python-Dev] PEP 460: allowing %d and %f and mojibake

On 12 January 2014 16:52, Kristján Valur Jónsson <kristjan at ccpgames.com> wrote:


But that's not what the current PEP says. It uses %s for interpolating
bytes values. It looks like you're saying that

b'abc %s' % (b'def')

will *not* produce b'abc def', but rather will produce b'abc b\'def\''
(because str(b'def'') is "b'def'").


More information about the Python-Dev mailing list