Here is a proposed patch.
One note on the patch. I feel the second sentence of the note is worth adding because value.__format__() departs from what PEP 3101 says:
"Note for Python 2.x: The 'format_spec' argument will be either
a string object or a unicode object, depending on the type of the
original format string. The __format__ method should test the type
of the specifiers parameter to determine whether to return a string or
unicode object. It is the responsibility of the __format__ method
to return an object of the proper type."
The extra sentence will help in heading off and when responding to issues about value.__format__() that are similar to issue 15951. |