(original) (raw)

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.