On 27 March 2014 21:24, Antoine Pitrou <solip...@pitrou.net> wrote:
> On Tue, 25 Mar 2014 15:37:11 -0700
> Ethan Furman <et...@stoneleaf.us> wrote:
>>
>> ``%a`` will call ``ascii()`` on the interpolated value.  This is intended
>> as a debugging aid, rather than something that should be used in production.
>> Non-ASCII values will be encoded to either ``\xnn`` or ``\unnnn``
>> representation.  Use cases include developing a new protocol and writing
>> landmarks into the stream; debugging data going into an existing protocol
>> to see if the problem is the protocol itself or bad data; a fall-back for a
>> serialization format; or even a rudimentary serialization format when
>> defining ``__bytes__`` would not be appropriate [8].
>
> The "use cases" you are enumerating for "%a" are chimeric. Did you
> *actually* do those things in real life, or are you inventing them for
> the PEP?

I'm the one that raised the "discourage misuse of __bytes__" concern,
so I'd like %a to stay in at least for that reason. %a is a perfectly
well defined format code (albeit one you'd only be likely to use while
messing about with serialisation protocols, as the PEP describes - for
example, if a %b code was ending up producing wrong data, you might
switch to %a temporarily to get a better idea of where the bad data
was coming from), while using __bytes__ to make %s behave the way %a
is defined in the PEP would just be wrong in most cases. I consider %a
the preemptive PEP 308 of binary interpolation format codes - in the
absence of %a, I'm certain that users would end up abusing __bytes__
and %s to get the same effect, just as they used the known bug magnet
that was the and/or hack for a long time in the absence of PEP 308.

I also seem to recall Guido saying he liked it, which flipped the
discussion from "do we have a good rationale for including it?" to "do
we have a good rationale for the BDFL to ignore his instincts?".
However, it would be up to Guido to confirm that recollection, and if
"Guido likes it" is part of the reason for inclusion of the %a code,
the PEP should mention that explicitly.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
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

Reply via email to