X Tutup
Skip to content

Commit ad4003c

Browse files
committed
Issue #25034: Merge from 3.4.
2 parents cb76496 + 85976b1 commit ad4003c

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

Lib/string.py

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

189189
def vformat(self, format_string, args, kwargs):
190190
used_args = set()
191-
result = self._vformat(format_string, args, kwargs, used_args, 2)
191+
result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
192192
self.check_unused_args(used_args, args, kwargs)
193193
return result
194194

@@ -235,14 +235,15 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth,
235235
obj = self.convert_field(obj, conversion)
236236

237237
# expand the format spec, if needed
238-
format_spec = self._vformat(format_spec, args, kwargs,
239-
used_args, recursion_depth-1,
240-
auto_arg_index=auto_arg_index)
238+
format_spec, auto_arg_index = self._vformat(
239+
format_spec, args, kwargs,
240+
used_args, recursion_depth-1,
241+
auto_arg_index=auto_arg_index)
241242

242243
# format the object and append to the result
243244
result.append(self.format_field(obj, format_spec))
244245

245-
return ''.join(result)
246+
return ''.join(result), auto_arg_index
246247

247248

248249
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
@@ -1012,6 +1012,7 @@ Tony Nelson
10121012
Trent Nelson
10131013
Chad Netzer
10141014
Max Neunhöffer
1015+
Anthon van der Neut
10151016
George Neville-Neil
10161017
Hieu Nguyen
10171018
Johannes Nicolai

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Core and Builtins
2121
Library
2222
-------
2323

24+
- Issue #25034: Fix string.Formatter problem with auto-numbering and
25+
nested format_specs. Patch by Anthon van der Neut.
26+
2427
- Issue #25233: Rewrite the guts of asyncio.Queue to be more understandable and correct.
2528

2629
- Issue #25203: Failed readline.set_completer_delims() no longer left the

0 commit comments

Comments
 (0)
X Tutup