[Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer (original) (raw)
Jim Jewett jimjjewett at gmail.com
Fri Sep 28 00:52:05 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 ]
On 9/26/07, Guido van Rossum <guido at python.org> wrote:
Comparisons -----------
The bytes and buffer types are comparable with each other and orderable, so that e.g. b'abc' == buffer(b'abc') < b'abd'.
I think bytes (regardless of length) should compare to integers, so that:
b"" < -sys.maxint < 97 == b'a' < b'aa' < 98
(zero-length buffer < any integer; otherwise compare the number to the first byte, and in case of ties, a BytesSequence of length 2 or more is greater)
I'm not as sure about comparing to floats.
Should they be incomparable to integer sequences?
(97, 98) != b'ab'
not (97, 98) < b'ab'
not (97, 98) > b'ab'
Bytes and the Str Type ----------------------
... any attempt to mix bytes (or buffer) objects and str objects without specifying an encoding will raise a TypeError exception. This is the case even for simply comparing a bytes or buffer object to a str object ...
Should a TypeError be raised as soon as you try to put a bytes and a string in the same dict, even if they don't happen to hash equal?
(I assume that buffer(b'abc') in {} will raise a TypeError, just as list("abc") in {} would.)
Therefore, support for the PEP 3118 buffer API will be removed from the str type.
Good; this may be the single biggest aid for separting characters from a particular (bytes) representation.
-jJ
- 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 ]