[Python-Dev] What to do for bytes in 2.6? (original) (raw)

Guido van Rossum guido at python.org
Sat Jan 19 20:32:46 CET 2008


On Jan 19, 2008 10:53 AM, Neil Schemenauer <nas at arctrix.com> wrote:

Guido van Rossum <guido at python.org> wrote: > bytes is an alias for str (not even a subclass) > b"" is an alias for ""

One advantage of a subclass is that there could be a flag that warns about combining bytes and unicode data. For example, b"x" + u"y" would produce a warning. As someone who writes internationalized software, I would happly use both the byte designating syntax and the warning flag, even if I wasn't planning to move to Python 3.

Yeah, that's what everybody thinks at first -- but the problem is that most of the time (in 2.6 anyway) the "bytes" object is something read from a socket, for example, not something created from a b"" literal. There is no way to know whether that return value means text or data (plenty of apps legitimately read text straight off a socket in 2.x), so the socket object can't return a bytes instance, and hence the warning won't trigger.

Really, the pure aliasing solution is just about optimal in terms of bang per buck. :-)

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



More information about the Python-Dev mailing list