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

Ethan Furman ethan at stoneleaf.us
Sat Jan 11 18:01:43 CET 2014

On 01/11/2014 12:43 AM, Nick Coghlan wrote:
> In particular, the bytes type is, and always will be, designed for
> pure binary manipulation [...]

I apologize for being blunt, but this is a lie.

Lets take a look at the methods defined by bytes:

>>> dir(b'')
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', 
'__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', 
'__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'center', 'count', 'decode', 'endswith', 'expandtabs', 
'find', 'fromhex', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 
'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 
'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

Are you really going to insist that expandtabs, isalnum, isalpha, isdigit, islower, isspace, istitle, isupper, ljust, 
lower, lstrip, rjust, splitlines, swapcase, title, upper, and zfill are pure binary manipulation methods?

Let's take a look at the repr of bytes:

>>> bytes([48, 49, 50, 51])

Wow, that sure doesn't look like binary data!

Py3 did not go from three text models to two, it went to one good one (unicode strings) and one broken one (bytes).  If 
the aim was indeed for pure binary manipulation, we failed.  We left in bunches of methods which can *only* be 
interpreted as supporting ASCII manipulation.

Due to backwards compatibility we cannot now finish yanking those out, so either we live with a half-dead class 
screaming "I want be ASCII!  I want to be ASCII!" or add back the missing functionality.


More information about the Python-Dev mailing list