On 3/27/2014 11:59 AM, Guido van Rossum wrote:
On Thu, Mar 27, 2014 at 11:52 AM, Daniel Holth <dho...@gmail.com
<mailto:dho...@gmail.com>> wrote:
I feel not including %s is nuts. Should I write .replace('%b', '%s')?
I assume you meant .replace('%s', '%b') (unless you're converting
Python 3 code to Python 2, which would mean you really are nuts :-).
But that's not going to help for the majority of code using %s -- as I
am trying to argue, %s doesn't mean "expect the argument to be a str"
and neither is that how it's commonly used (although it's *possible*
that that is how *you* use it exclusively -- that doesn't make you
nuts, just more strict than most people).
That _is_ how it is commonly used in Py2 when dealing with binary data
in mixed ASCII/binary protocols, is what I've been hearing in this
discussion, and what small use I've made of Py2 when some unported
module forced me to use it (I started Python about the time Py3 was
released)... the expected argument is a (Py2) str containing binary data
(would be bytes in Py3).
While there are many other reasons to use %s in other coding situations,
this is the only way to do bytes interpolations using %. And there is no
%b in Py2, so for Py2/3 compatibility, %s needs to do bytes
interpolations in Py3. And if it does, there is no need for %b in Py3 %,
because they would be identical and redundant.
All I desperately need are APIs that provide enough unicode / str type
safety that I get an exception when mixing them accidentally... in my
own code, dynamic typing is usually a bug. As has been endlessly
discussed, %s for bytes is a bit like exposing sprintf()...
I don't understand that last claim (I can't figure out whether in this
context is exposing sprintf() is considered good or bad). But apart
from that, can you give some specific examples?
PS. I am not trying to be difficult. I honestly don't understand the
use case yet, and the PEP doesn't do much to support it.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com