[Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer (original) (raw)
Guido van Rossum guido at python.org
Thu Sep 27 01:03:12 CEST 2007
- Previous message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Next message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[PEP 3137]
> Open Issue: I'm undecided on whether indexing bytes and buffer > objects should return small ints (like the bytes type in 3.0a1, and > like lists or array.array('B')), or bytes/buffer objects of length 1 > (like the str type). The latter (str-like) approach will ease porting > code from Python 2.x; but it makes it harder to extract values from a > bytes array.
On 9/26/07, Brett Cannon <brett at python.org> wrote:
How much do you care about making the 2 -> 3 transition easy? If you don't go the str way then comparisons like
bytes[0] == b"A"
won't work unless you allow comparisons between ints and length 1 bytes/buffers. Extracting a single item is not horrendous if you pass it to int().Personally I say go with the list-like semantics. Having the following code return false seems odd (but not ridiculous) to me:: stuff = bytes([0, 1]) stuff[1] = 42 stuff[1] == 42 So unless int comparisons are allowed I am -0 on the str-like semantics.
int comparisons would stick out like a sore thumb, especially since they can only be reasonably made to work on 1-byte strings.
I'm still undecided (despite Marcin's eloquent argument for ints as bytes) but I'm open for votes for this case.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Next message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]