<p dir="ltr"><br>
On 25 Feb 2014 05:44, "Antoine Pitrou" <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
><br>
> On Mon, 24 Feb 2014 10:40:46 -0800<br>
> Ethan Furman <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:<br>
><br>
> > Okay, types corrected, most comments taken into account.<br>
> ><br>
> > %b is right out, %a is still suffering scrutiny.<br>
> ><br>
> > The arguments seem to boil down to:<br>
> ><br>
> > We don't need it.<br>
> ><br>
> > vs<br>
> ><br>
> > Somebody might, and it's better than having them inappropriately add a __bytes__ method if we don't have it.<br>
><br>
> Don't forget that Python is a language for consenting adults. Adding a<br>
> near-useless feature for fear that otherwise people might shoot<br>
> themselves in the foot by using another feature must be one of the<br>
> worst arguments I've ever heard :-)</p>
<p dir="ltr">That's not quite the argument. The argument is that __bytes__ is expected to work in arbitrary binary contexts and hence should *never* assume ASCII compatibility (the PEP should probably propose a new addition to PEP 8 to that effect), so the question is then "OK, since it isn't defining __bytes__, what is the preferred spelling for getting the ASCII compatible representation of an object as a byte sequence?".</p>

<p dir="ltr">If we do nothing, then that spelling is "ascii(obj).encode('ascii')".</p>
<p dir="ltr">If %a is allowed as part of a binary interpolation pattern, then it becomes "b'%a' % obj"</p>
<p dir="ltr">Allowing %a also improves the consistency with text interpolation. In the case of %r, the inconsistency is based on needing to disallow arbitrary Unicode code points in the result and not wanting to redefine %r as a second way to spell %a. There's no corresponding reason to disallow %a - the result is guaranteed to be ASCII compatible, so there's no risk of data driven encoding errors, and no difference between doing the binary interpolation directly, or doing text interpolation and then encoding the result as ASCII. </p>

<p dir="ltr">As far as use cases go, as someone else mentioned, the main one is likely to be binary logging and error reporting formats, as it becomes a quick and easy way to embed a backslash escaped string. However, my interest is more in providing an obvious way to do it and in minimising the differences between text and binary interpolation.</p>

<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> Regards<br>
><br>
> Antoine.<br>
><br>
><br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>