changeset: 90350:b1aba042b36c user: Eric V. Smith date: Tue Apr 15 22:37:55 2014 -0400 files: Lib/test/test_types.py Misc/NEWS Python/formatter_unicode.c description: Close issue #8931: Make alternate formatting for 'c' raise an exception. Patch by Torsten Landschoff. diff -r 9e1d2150fff2 -r b1aba042b36c Lib/test/test_types.py --- a/Lib/test/test_types.py Tue Apr 15 22:28:40 2014 -0400 +++ b/Lib/test/test_types.py Tue Apr 15 22:37:55 2014 -0400 @@ -343,6 +343,8 @@ self.assertRaises(ValueError, 3 .__format__, ",n") # can't have ',' with 'c' self.assertRaises(ValueError, 3 .__format__, ",c") + # can't have '#' with 'c' + self.assertRaises(ValueError, 3 .__format__, "#c") # ensure that only int and float type specifiers work for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] + diff -r 9e1d2150fff2 -r b1aba042b36c Misc/NEWS --- a/Misc/NEWS Tue Apr 15 22:28:40 2014 -0400 +++ b/Misc/NEWS Tue Apr 15 22:37:55 2014 -0400 @@ -43,6 +43,10 @@ replacement fields. It now matches the behavior of str.format() in this regard. Patches by Phil Elson and Ramchandra Apte. +- Issue #8931: Make alternate formatting ('#') for type 'c' raise an + exception. In versions prior to 3.5, '#' with 'c' had no effect. Now + specifying it is an error. Patch by Torsten Landschoff. + Library ------- diff -r 9e1d2150fff2 -r b1aba042b36c Python/formatter_unicode.c --- a/Python/formatter_unicode.c Tue Apr 15 22:28:40 2014 -0400 +++ b/Python/formatter_unicode.c Tue Apr 15 22:37:55 2014 -0400 @@ -846,6 +846,13 @@ " format specifier 'c'"); goto done; } + /* error to request alternate format */ + if (format->alternate) { + PyErr_SetString(PyExc_ValueError, + "Alternate form (#) not allowed with integer" + " format specifier 'c'"); + goto done; + } /* taken from unicodeobject.c formatchar() */ /* Integer input truncated to a character */