diff -r 80a50b7ad88f Lib/string.py --- a/Lib/string.py Mon Feb 13 20:28:46 2012 +0200 +++ b/Lib/string.py Mon Feb 13 20:54:03 2012 +0100 @@ -195,7 +195,7 @@ # expand the format spec, if needed format_spec = self._vformat(format_spec, args, kwargs, - used_args, recursion_depth-1) + used_args, recursion_depth - 1) # format the object and append to the result result.append(self.format_field(obj, format_spec)) @@ -220,12 +220,14 @@ def convert_field(self, value, conversion): # do any conversion on the resulting object - if conversion == 'r': - return repr(value) + if conversion is None: + return value elif conversion == 's': return str(value) - elif conversion is None: - return value + elif conversion == 'r': + return repr(value) + elif conversion == 'a': + return ascii(value) raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) diff -r 80a50b7ad88f Lib/test/test_string.py --- a/Lib/test/test_string.py Mon Feb 13 20:28:46 2012 +0200 +++ b/Lib/test/test_string.py Mon Feb 13 20:54:03 2012 +0100 @@ -38,6 +38,9 @@ self.assertEqual(fmt.format("{0!s}", 'test'), 'test') self.assertRaises(ValueError, fmt.format, "{0!h}", 'test') + # issue13579 + self.assertEqual(fmt.format("{0!a}", 42), '42') + def test_name_lookup(self): fmt = string.Formatter() class AnyAttr: