[issue15951] string.Formatter returns str for empty unicode template

Chris Jerdonek report at bugs.python.org
Wed Sep 19 02:38:54 CEST 2012


Chris Jerdonek added the comment:

Attached is a proposed patch.

Some explanation behind the patch that stems from the above comments:

The following is an example of Formatter.format() returning str in the current implementation that would break if we made Formatter.format() return unicode whenever format_string is unicode:

>>> f.format(u"{0}", "\xc3\xa9")  # UTF-8 encoded "e-acute".
'\xc3\xa9'

(It would break with a UnicodeDecodeError because 'ascii' is the default encoding.)

Since we can't change Formatter.format(format_string) to return unicode whenever format_string is unicode without breaking existing code, I believe the best we can do is to document the departure from PEP 3101.  Since the caller has to handle return values of type str anyways, I don't think it helps to ensure that more return values are unicode.

----------
Added file: http://bugs.python.org/file27222/issue-15951-2-branch27.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15951>
_______________________________________


More information about the Python-bugs-list mailing list