[Python-Dev] The bytes type (was Re: Warning for 2.6 and greater) (original) (raw)
Guido van Rossum guido at python.org
Fri Jan 12 18:51:25 CET 2007
- Previous message: [Python-Dev] The bytes type (was Re: Warning for 2.6 and greater)
- Next message: [Python-Dev] The bytes type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 1/12/07, A.M. Kuchling <amk at amk.ca> wrote:
On Fri, Jan 12, 2007 at 10:14:57AM -0500, Barry Warsaw wrote: > I think there will be at least three areas that will make porting a > challenge: ... > - - Unicode/str/bytes incompatibilities
Something I've been meaning to bring up... do we know what shape the Unicode/str/bytes resolution will take? It would be nice to know so that similar changes can be made to Jython. For example, str in Jython is a Unicode type, but things like the MD5 module should really only be dealing with 8-bit strings.
This hasn't been sorted out in much detail, alas. I expect we'll have some tough decisions to make about which APIs use bytes and which use str. (For another example, considere base64.)
Is PEP 358 still the current thinking on the bytes type? If yes, should we set about implementing it for Jython and Python 2.6?
I'm afraid that PEP is not up to date; I don't think I used it as a reference when I coded up the current bytes type in Py3k. Whenever the PEP matches the implementation, we can be confident that we have the right design. Where they differ, I'd be inclined to believe the code, unless it's a matter of an as-yet-unimplemented feature, or a temporary measure while we still have the 8-bit str type.
Some examples of differences:
bytes(100) returns a bytes array of length 100 filled with zeros.
repr() of a bytes array uses hex notation instead of decimal.
.fromhex() and .hex() are not implemented.
.append(), .insert(), .remove(), .pop(), .extend(), .index(), .count() are not implemented.
bytes has .decode() and .join() methods that are not in the PEP.
In general I believe the actual bytes object resembles strings more than lists, and probably will grow more string-like behavior instead of more list methods. (Case in point: 'in' implements a substring check like strings do.)
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] The bytes type (was Re: Warning for 2.6 and greater)
- Next message: [Python-Dev] The bytes type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]