[Python-Dev] PEP 461 - Adding % and {} formatting to bytes

Glenn Linderman v+python at g.nevcal.com
Wed Jan 15 22:04:41 CET 2014

On 1/15/2014 7:52 AM, Eric V. Smith wrote:
> So basically I think we'll have to hard-code the types that .format()
> will support, and never call __format__, or only call __format__ if we
> know that it's a exact type where we know that __format__ will return
> (strict ASCII).
> Either that, or we're back to encoding the result of __format__ and
> accepting that sometimes it might throw errors, depending on the values
> being passed into format().

Looks like you need to invent  __formatb__ to produce only ASCII. 
Objects that have __formatb__ can be formatted by bytes.format.  To 
avoid coding, it could be possible that __formatb__ might be a callable, 
in which case it is called to get the result, or not a callable, in 
which case one calls __format__ and converts the result to ASCII, 
__formatb__ just indicating a guarantee that only ASCII will result.

Or it could be that __formatb__ replaces __format__ and str.__format__, 
if it finds no __format__ looks for __formatb__, calls that, and 
converts the result to Unicode.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140115/deba74a3/attachment.html>

More information about the Python-Dev mailing list