diff -r eb018a4dad3c -r 63a81867eb17 Lib/test/test_str_jy.py --- a/Lib/test/test_str_jy.py Thu Jul 25 11:12:30 2013 -0700 +++ b/Lib/test/test_str_jy.py Wed Aug 21 14:03:21 2013 -0700 @@ -53,6 +53,10 @@ self.assertEquals("%+f" % -5, "-5.000000") self.assertEquals("%+f" % 5, "+5.000000") + def test_format_issue2075(self): + self.assertEquals("%#018x" % 14, "0x000000000000000e") + self.assertEquals("{:#018x}".format(14), "0x000000000000000e") + self.assertEquals("{:+#018X}".format(14), "+0X00000000000000E") def test_argument_count_exception(self): "exception thrown when too many or too few arguments for format string" diff -r eb018a4dad3c -r 63a81867eb17 src/org/python/core/stringlib/InternalFormatSpec.java --- a/src/org/python/core/stringlib/InternalFormatSpec.java Thu Jul 25 11:12:30 2013 -0700 +++ b/src/org/python/core/stringlib/InternalFormatSpec.java Wed Aug 21 14:03:21 2013 -0700 @@ -30,6 +30,28 @@ leading = 0; } char fill = fill_char != 0 ? fill_char : ' '; + switch (sign) { + case '+': + case ' ': + if (value.charAt(0) == sign) { + result.append(sign); + value = value.substring(1); + } + break; + } + if (alternate) { + char alt_char = value.charAt(1); + switch (alt_char) { + case 'b': + case 'o': + case 'x': + case 'X': + result.append(value.charAt(0)); + result.append(value.charAt(1)); + value = value.substring(2); + break; + } + } for (int i = 0; i < leading; i++) { result.append(fill); }