[Python-ideas] Bytestrings in Python 2
Serhiy Storchaka
storchaka at gmail.com
Sat Apr 25 18:14:57 CEST 2015
Here is an idea that perhaps will help to prepare Python 2 code for
converting to Python 3.
Currently bytes is just an alias of str in Python 2, and the "b" prefix
of string literals is ignored. There are no differences between natural
strings and bytes. I propose to add special bit to str instances and set
it for bytes literals and strings created from binary sources (read from
binary files, received from sockets, the result of unicode.encode() and
struct.pack(), etc). With -3 flag operations with binary strings that
doesn't allowed for bytes in Python 3 (e.g. encoding or coercing to
unicode) will emit a warning. Unfortunately we can't change the bytes
constructor in minor version, it should left an alias to str in 2.7. So
the result of bytes() will be not tagged as binary string.
May be it is too late for this.
More information about the Python-ideas
mailing list