diff -r 6cd736239b8a -r dd3992754141 Lib/test/test_types.py --- a/Lib/test/test_types.py Sat Dec 10 21:25:04 2011 +0100 +++ b/Lib/test/test_types.py Sat Dec 10 22:20:23 2011 +0100 @@ -340,6 +340,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 6cd736239b8a -r dd3992754141 Python/formatter_unicode.c --- a/Python/formatter_unicode.c Sat Dec 10 21:25:04 2011 +0100 +++ b/Python/formatter_unicode.c Sat Dec 10 22:20:23 2011 +0100 @@ -792,6 +792,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 */