[Python-Dev] bytes type discussion
bokr at oz.net
Thu Feb 16 01:43:24 CET 2006
On Wed, 15 Feb 2006 15:20:16 -0800, Guido van Rossum <guido at python.org> wrote:
>I'm actually assuming to put this off until 2.6 anyway.
>On 2/15/06, Fredrik Lundh <fredrik at pythonware.com> wrote:
>> Thomas Wouters wrote:
>> > > After reading some of the discussion, and seen some of the arguments,
>> > > I'm beginning to feel that we need working code to get this right.
>> > >
>> > > It would be nice if we could get a bytes() type into the first alpha, so
>> > > the design can get some real-world exposure in real-world apps/libs be-
>> > > fore 2.5 final.
>> > I agree that working code would be nice, but I don't see why it should be in
>> > an alpha release. IMHO it shouldn't be in an alpha release until it at least
>> > looks good enough for the developers, and good enough to put in a PEP.
>> I'm not convinced that the PEP will be good enough without experience
>> from using a bytes type in *real-world* (i.e. *existing*) byte-crunching
>> if we put it in an early alpha, we can use it with real code, fix any issues
>> that arises, and even remove it if necessary, before 2.5 final. if it goes in
>> late, we'll be stuck with whatever the PEP says.
I could hardly keep up with reading, never mind trying some things
and writing coherently, so if others had that experience, 2.6 sounds +1.
I agree with Fredrik that an implementation to try in real-world use cases
would probably yield valuable information.
As a step in that direction, could we have a sub-thread on what methods
to implement for bytes?
I.e., which str methods make sense, which special methods? How many methods
from list make sense, given that bytes will be mutable? How much of array.array('B')
should be emulated? (a protype hack could just wrap array.array for storage).
Should the type really be a subclass of int? I think that might be hard for
prototyping, since builtin types as bases seem to get priority subclass bypass
access from some builtin functions. At least I've had some frustrations with that.
If it were a kind of int, would it be an int-string, where int(bytes()) would work
like ord does with non-length-1? BTW bytes([1,2]) by analogy to str should
then return bytes(), shouldn't it? I have a feeling a lot of str-like methods
will bomb if that's not so.
>>> int(bytes([1,2])) # faked ;-)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: int() expected a byte, but bytes of length 2 found
I've hacked a few pieces, but I think further discussion either in this thread
or maybe a bytes prototype spec thread would be fruitful.
By the time a prototype spec takes shape, someone will probably have beaten me
to something workable, but that's ok ;-)
Then a PEP will mostly be writing and collecting rationale references etc.
That's really not my favorite kind of work, frankly. But I like thinking and programming.
More information about the Python-Dev