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

R. David Murray rdmurray at bitdance.com
Tue Feb 21 02:24:16 CET 2012


Two patches have been committed to 3.3 that I am very uncomfortable with.
See issue 13637 and issue 13641, respectively.

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,
and I think it will lead to the same kind of bugs that automatic string
coercions yielded in Python2: a program works fine until the input
turns out to have non-ASCII data in it, and then it blows up with an
unexpected UnicodeError.  You can see Antoine's counter arguments in the
issue, and I'm sure he'll chime in here.

If most people agree with Antoine I won't fight it, but it seems to me
that accepting unicode in the binascii and base64 APIs is a bad idea.

I'm on vacation this week so I may not be very responsive on this thread,
but unless other people agree with me (and will therefore advance the
relevant arguments) the thread can die and the patches can stay in.

--David


More information about the Python-Dev mailing list