[Python-ideas] Bytestrings in Python 2
Markus Unterwaditzer
markus at unterwaditzer.net
Sat Apr 25 21:27:36 CEST 2015
On Sat, Apr 25, 2015 at 07:14:57PM +0300, Serhiy Storchaka wrote:
> 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.
You can get similar kinds of warnings with unicode-nazi
(https://github.com/mitsuhiko/unicode-nazi), so I'm not sure if this would be
that helpful.
-- Markus
More information about the Python-ideas
mailing list