Skip to content

Commit 6dcada3

Browse files
committed
Issue #25034: Merge from 3.5.
2 parents 2fbcd2a + ad4003c commit 6dcada3

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

Lib/string.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def format(*args, **kwargs):
183183

184184
def vformat(self, format_string, args, kwargs):
185185
used_args = set()
186-
result = self._vformat(format_string, args, kwargs, used_args, 2)
186+
result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
187187
self.check_unused_args(used_args, args, kwargs)
188188
return result
189189

@@ -230,14 +230,15 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth,
230230
obj = self.convert_field(obj, conversion)
231231

232232
# expand the format spec, if needed
233-
format_spec = self._vformat(format_spec, args, kwargs,
234-
used_args, recursion_depth-1,
235-
auto_arg_index=auto_arg_index)
233+
format_spec, auto_arg_index = self._vformat(
234+
format_spec, args, kwargs,
235+
used_args, recursion_depth-1,
236+
auto_arg_index=auto_arg_index)
236237

237238
# format the object and append to the result
238239
result.append(self.format_field(obj, format_spec))
239240

240-
return ''.join(result)
241+
return ''.join(result), auto_arg_index
241242

242243

243244
def get_value(self, key, args, kwargs):

Lib/test/test_string.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_auto_numbering(self):
5858
'foo{1}{num}{1}'.format(None, 'bar', num=6))
5959
self.assertEqual(fmt.format('{:^{}}', 'bar', 6),
6060
'{:^{}}'.format('bar', 6))
61+
self.assertEqual(fmt.format('{:^{}} {}', 'bar', 6, 'X'),
62+
'{:^{}} {}'.format('bar', 6, 'X'))
6163
self.assertEqual(fmt.format('{:^{pad}}{}', 'foo', 'bar', pad=6),
6264
'{:^{pad}}{}'.format('foo', 'bar', pad=6))
6365

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ Tony Nelson
10131013
Trent Nelson
10141014
Chad Netzer
10151015
Max Neunhöffer
1016+
Anthon van der Neut
10161017
George Neville-Neil
10171018
Hieu Nguyen
10181019
Johannes Nicolai

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ Core and Builtins
190190
Library
191191
-------
192192

193+
- Issue #25034: Fix string.Formatter problem with auto-numbering and
194+
nested format_specs. Patch by Anthon van der Neut.
195+
193196
- Issue #25233: Rewrite the guts of asyncio.Queue to be more understandable and correct.
194197

195198
- Issue #23600: Default implementation of tzinfo.fromutc() was returning

0 commit comments

Comments
 (0)