[Python-Dev] What to do for bytes in 2.6?

Guido van Rossum guido at python.org
Fri Jan 18 02:09:46 CET 2008


I believe the issue of whether and how to backport bytes (and
bytearray?) from 3.0 to 2.6 has come up before, but I don't think
we've come to any kind of conclusion. It's quite subtle. In a private
email, Thomas Wouters and I discussed this:

[Guido]
> > Perhaps the biggest question in my mind is what to do with bytes in
> > 2.6. Make it an alias for str? Or a new type that doesn't mix with
> > either str or unicode? But then how do we get read() calls and the
> > like on binary files or sockets to return bytes instances? Perhaps a
> > trivial str subclass? Or return bytes when -3 is specified? I need to
> > bring this up on the list.

[Thomas]
> I don't know yet. I'm not sure yet what to do with strings and unicode in
> 2.6 in -3 mode (or perhaps through a future-import, with some hackery.)
> Perhaps a *set* of str-subclasses makes sense: a will-be-unicode subclass,
> and a will-be-bytes subclass. String literals and text-mode input would
> produce will-be-unicode, binary input and byte literals will-be-bytes.
> Switching between -3 and normal mode for that would be changing a few
> pointers in the core, making all operations return normal strings in normal
> mode. And the would-be types can produce whatever warning they wish -- they
> need not worry about speed. But I'm not sure if that'll work.

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


More information about the Python-Dev mailing list