[Python-3000] bytes & Py_TPFLAGS_BASETYPE

Mathieu Fenniak mathieu.fenniak at gmail.com
Mon Sep 17 05:19:34 CEST 2007


On 16-Sep-07, at 7:56 PM, Guido van Rossum wrote:
> So suppose my answer was "no, bytes won't be subclassable". How much
> would you really lose by having to wrap a separate object around a
> bytes object, rather than being able to subclass? How much extra code
> do you think you would have to write?
>
> Another way to look at it-- how much of the bytes type's API do your
> objects really have to support?

Most often, I'd be concatenating and comparing with other bytes  
objects, iterating through the byte array, and passing the byte array  
into methods like stream.write.  Iterating and comparing could be  
dealt with by some code in the containing class; for other needs, I  
would sprinkle ".data" property accesses throughout the code to  
access the bytes instance.

I'm not too concerned about the programming I'd have to do, even  
though the end result wouldn't really be what I'd like to have.  It's  
not the end of the world, it's just not ideal.

I do think that subclassing bytes would probably be a request a few  
people would have, especially when porting Python 2 code that  
subclasses str.  It seems especially unusual that bytes can't be  
subclassed, when builtin types like str, list, dict, and set can be.

Mathieu


More information about the Python-3000 mailing list