[Python-Dev] accept string in a2b and base64?

Antoine Pitrou solipsis at pitrou.net
Tue Feb 21 02:47:22 CET 2012


On Mon, 20 Feb 2012 20:24:16 -0500
"R. David Murray" <rdmurray at bitdance.com> wrote:
> 
> It seems to me that part of the point of the byte/string split (and the
> lack of automatic coercion) is to make the programmer be explicit about
> converting between unicode and bytes.  Having these functions, which
> convert between binary formats (ASCII-only representations of binary data
> and back) accept unicode strings is reintroducing automatic coercions,

Whether a baseXX representation is binary or text can probably be
argued endlessly. As a data point, hex() returns str, not bytes, so at
least base16 can be considered (potentially) text. And the point of
baseXX representations is generally to embed binary data safely into
text, which explains why you may commonly need to baseXX-decode some
chunk of text. This occurred to me when porting Twisted to py3k; I'm
sure other networking code would also benefit.

Really, I think there's no problem with coercions when they are
unambiguous and safe (which they are, in the committed patches). They
make writing and porting code easier.
For example, we already have:

>>> int("10")
10
>>> int(b"10")
10

Regards

Antoine.




More information about the Python-Dev mailing list