[Python-ideas] format specifier for "not bytes"
Nick Coghlan
ncoghlan at gmail.com
Sat Aug 25 01:16:18 CEST 2012
A couple of people at PyCon Au mentioned running into this kind of issue
with Python 3. It relates to the fact that:
1. String formatting is *coercive* by default
2. Absolutely everything, including bytes objects can be coerced to a
string, due to the repr() fallback
So it's relatively easy to miss a decode or encode operation, and end up
interpolating an unwanted "b" prefix and some quotes.
For existing versions, I think the easiest answer is to craft a regex that
matches bytes object repr's and advise people to check that it *doesn’t*
match their formatted strings in their unit tests.
For 3.4+ a non-coercive string interpolation format code may be desirable.
Cheers,
Nick.
--
Sent from my phone, thus the relative brevity :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120825/ca6d4bba/attachment.html>
More information about the Python-ideas
mailing list