diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/string.py | 11 | ||||
-rw-r--r-- | Lib/test/test_string.py | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/Lib/string.py b/Lib/string.py index e7b692d..1add44b 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -183,7 +183,7 @@ class Formatter: def vformat(self, format_string, args, kwargs): used_args = set() - result = self._vformat(format_string, args, kwargs, used_args, 2) + result, _ = self._vformat(format_string, args, kwargs, used_args, 2) self.check_unused_args(used_args, args, kwargs) return result @@ -230,14 +230,15 @@ class Formatter: obj = self.convert_field(obj, conversion) # expand the format spec, if needed - format_spec = self._vformat(format_spec, args, kwargs, - used_args, recursion_depth-1, - auto_arg_index=auto_arg_index) + format_spec, auto_arg_index = self._vformat( + format_spec, args, kwargs, + used_args, recursion_depth-1, + auto_arg_index=auto_arg_index) # format the object and append to the result result.append(self.format_field(obj, format_spec)) - return ''.join(result) + return ''.join(result), auto_arg_index def get_value(self, key, args, kwargs): diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index 5d37e16..0cd2b86 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -58,6 +58,8 @@ class ModuleTest(unittest.TestCase): 'foo{1}{num}{1}'.format(None, 'bar', num=6)) self.assertEqual(fmt.format('{:^{}}', 'bar', 6), '{:^{}}'.format('bar', 6)) + self.assertEqual(fmt.format('{:^{}} {}', 'bar', 6, 'X'), + '{:^{}} {}'.format('bar', 6, 'X')) self.assertEqual(fmt.format('{:^{pad}}{}', 'foo', 'bar', pad=6), '{:^{pad}}{}'.format('foo', 'bar', pad=6)) |