"Byte" type?

Benjamin Kaplan benjamin.kaplan at case.edu
Sat Feb 21 14:02:19 EST 2009


On Sat, Feb 21, 2009 at 12:21 PM, John Nagle <nagle at animats.com> wrote:

> Steve Holden wrote:
>
>> John Nagle wrote:
>>
>>> Steve Holden wrote:
>>>
>>>> John Nagle wrote:
>>>>
>>>>> Benjamin Kaplan wrote:
>>>>>
>>>>>> On Sun, Feb 15, 2009 at 11:57 AM, John Nagle <nagle at animats.com>
>>>>>> wrote:
>>>>>>
>>>>>>  ...Re "bytes" not behaving as documented in 2.6:
>>>
>>>    That's indeed how Python 2.6 works.  But that's not how
>>>>> PEP 3137 says it's supposed to work.
>>>>>
>>>>> Guido:
>>>>>
>>>>>  "I propose the following type names at the Python level:
>>>>>
>>>>>        * bytes is an immutable array of bytes (PyString)
>>>>>        * bytearray is a mutable array of bytes (PyBytes)"
>>>>>
>>>> ...
>>>
>>>> (Not true in Python 2.6
>>>>> Is this a bug, a feature, a documentation error, or bad design?
>>>>>
>>>>>  It's a feature. In fact all that was done to accommodate easier
>>>> migration to 3.x is easily shown in one statement:
>>>>
>>>>  str is bytes
>>>>>>>
>>>>>> True
>>>>
>>>> So that's why bytes works the way it does in 2.6 ... hence my contested
>>>> description of it as an "ugly hack". I am happy to withdraw "ugly", but
>>>> I think "hack" could still be held to apply.
>>>>
>>>   Agreed.  But is this a 2.6 thing, making 2.6 incompatible with 3.0, or
>>> what?  How will 3.x do it?  The PEP 3137 way, or the Python 2.6 way?
>>>
>>>   The way it works in 2.6 makes it necessary to do "ord" conversions
>>> where they shouldn't be required.
>>>
>>>  Yes, the hack was to achieve a modicum of compatibility with 3.0 without
>> having to turn the world upside down.
>>
>> I haven't used 3.0 enough the say whether bytearray has been correctly
>> implemented. But I believe the intention is that 3.0 should fully
>> implement PEP 3137.
>>
>
>   If "bytes", a new keyword, works differently in 2.6 and 3.0, that was
> really
> dumb.  There's no old code using "bytes".  So converting code to 2.6 means
> it has to be converted AGAIN for 3.0.  That's a good reason to ignore 2.6
> as
> defective.
>

"""

The primary use of bytes in 2.6 will be to write tests of object type such
as isinstance(x, bytes). This will help the 2to3 converter, which can't tell
whether 2.x code intends strings to contain either characters or 8-bit
bytes; you can now use either bytes or
str<http://docs.python.org/library/functions.html#str>to represent
your intention exactly, and the resulting code will also be
correct in Python 3.0.

"""

The reason for putting bytes (a new type, not a keyword) into 2.6 was purely
for use in the 2to3 tool. It is designed to break less code on the
conversion from 2.x to 3.x, not to add extra features to 2.6+.


>
>                                        John Nagle
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090221/f51914ef/attachment-0001.html>


More information about the Python-list mailing list