[Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

Mark Shannon mark at hotpy.org
Wed Jan 8 10:13:46 CET 2014

On 06/01/14 13:24, Victor Stinner wrote:
> Hi,
> bytes % args and bytes.format(args) are requested by Mercurial and

I'm opposed to adding methods to bytes for this, as I think it goes 
against the reason for the separation of str and bytes in the first place.

str objects are pieces of text, a list of unicode characters.
In other words they have meaning independent of their context.

bytes are just a sequence of 8bit clumps.
The meaning of bytes depends on the encoding, but the proposed methods 
will have no encoding, but presume meaning.
What does b'%s' % 7 do?
u'%s' % 7 calls 7 .__str__() which returns a (unicode) string.
By implication b'%s' % 7 would call 7 .__str__() and ...
And then what? Use the "default" encoding? ASCII?
Explicit is better than implicit.

I am not opposed to adding new functionality, as long as it is not 
overloading the % operator or format() method.

binascii.format() perhaps?


More information about the Python-Dev mailing list