[Python-3000] Immutable bytes type and bsddb or other IO

Guido van Rossum guido at python.org
Sat Aug 25 04:19:12 CEST 2007


On 8/24/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > there's collusion between the bytes and unicode
> > types so that this works:
> >
> >   b = b"abc"
> >   b[1:2] = "X"
>
> Is this intentional? Doesn't it run counter to the idea
> that text and bytes should be clearly separated?

Sorry, I wasn't clear. I was describing the status quo, which I am as
unhappy about as you are.

> > Unfortunately taking the buffer API away from unicode makes things
> > fail early
>
> If the buffer API distinguishes between text and binary
> buffers, then the binary streams can just accept binary
> buffers only, and unicode can keep its buffer API.

Yes, but the bytes object is the one doing the work, and for some
reason that I don't yet fathom it asks for character buffers. Probably
because there are tons of places where str and bytes are still being
mixed. :-(

I tried to change the bytes constructor so that bytes(s) is invalid if
isinstance(s, str), forcing one to use bytes(s, <encoding>). This
caused many failures, some of which I could fix, others which seem to
hinge on a fundamental problem (asserting that bytes objects support
the string API).

More work to do... :-(

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list