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

2020-05-31 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- resolution: -> out of date stage: needs patch -> resolved status: open -> closed ___ Python tracker ___

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

2012-09-22 Thread Chris Jerdonek
Changes by Chris Jerdonek chris.jerdo...@gmail.com: -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15951 ___ ___

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

2012-09-18 Thread Chris Jerdonek
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

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

2012-09-16 Thread Aleksey Sivokon
New submission from Aleksey Sivokon: Expected behavior of string.Formatter() is to return unicode strings for unicode templates, and byte strings for str templates. Which is exactly what it does, with one frustrating exception: for empty unicode string it returns byte str. Test follows:

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

2012-09-16 Thread Chris Jerdonek
Chris Jerdonek added the comment: Adding failing test. Patch coming next. -- keywords: +patch nosy: +cjerdonek stage: - needs patch Added file: http://bugs.python.org/file27204/issue-15951-test-1.patch ___ Python tracker rep...@bugs.python.org

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

2012-09-16 Thread Chris Jerdonek
Chris Jerdonek added the comment: Here are some related failing cases that I found: f = string.Formatter() f.format(u{0}, ) '' f.format(u{0}, 1) '1' f.format(u{0}, a) 'a' f.format(u{0}{1}, a, b) 'ab' f.format({0}, ua) u'a' Note that PEP 3101 says the following: In all cases, the type

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

2012-09-16 Thread Chris Jerdonek
Chris Jerdonek added the comment: Actually, I'm going to defer on creating a patch because this covers more scenarios than I originally thought and so may require more time. -- ___ Python tracker rep...@bugs.python.org

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

2012-09-16 Thread R. David Murray
R. David Murray added the comment: Format with unicode is a bit of a mess in 2.7. It would be consistent with the rest of python2 for f.format({0}, ua) u'a' to be correct. See also issue 7300 and issue 15276. -- nosy: +eric.smith, r.david.murray

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

2012-09-16 Thread Chris Jerdonek
Chris Jerdonek added the comment: What about cases like this? f.format(u'{0}', '\xe9') '\xe9' It seems fixing this issue for non-empty strings would cause formerly running cases like this to raise UnicodeDecodeError. unicode('\xe9') ... UnicodeDecodeError: 'ascii' codec can't decode byte

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

2012-09-16 Thread R. David Murray
R. David Murray added the comment: Note that I didn't say it was correct, I just said it was consistent :) And no, breaking stuff that current works is a non-starter for 2.7. -- ___ Python tracker rep...@bugs.python.org

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

2012-09-16 Thread Chris Jerdonek
Chris Jerdonek added the comment: I filed issue 15952 for the behavior difference between format(value) and value.__format__() and the related lack of documentation re: unicode format strings. Given that the expected behavior for the current issue doesn't seem to be documented (aside from