summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2015-09-29 10:30:04 -0400
committerEric V. Smith <eric@trueblade.com>2015-09-29 10:30:04 -0400
commitad4003c7fb9072c2697480ee84440408f7a49cd9 (patch)
treed0b40b8cae2b95150fcbff61acab9fad0d437e7c
parentcb764960c917ba9b91cb7dc3aebf4b642f62167d (diff)
parent85976b14ddb941670ee831ed18b5bc69ca1380ac (diff)
downloadcpython-git-ad4003c7fb9072c2697480ee84440408f7a49cd9.tar.gz
Issue #25034: Merge from 3.4.
-rw-r--r--Lib/string.py11
-rw-r--r--Lib/test/test_string.py2
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 12 insertions, 5 deletions
diff --git a/Lib/string.py b/Lib/string.py
index f3365c67fb..62e8f2f059 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -188,7 +188,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
@@ -235,14 +235,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 5d37e164cf..0cd2b86217 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))
diff --git a/Misc/ACKS b/Misc/ACKS
index 44582eab77..6999c0909c 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1012,6 +1012,7 @@ Tony Nelson
Trent Nelson
Chad Netzer
Max Neunhöffer
+Anthon van der Neut
George Neville-Neil
Hieu Nguyen
Johannes Nicolai
diff --git a/Misc/NEWS b/Misc/NEWS
index d352296beb..5a7784466c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,9 @@ Core and Builtins
Library
-------
+- Issue #25034: Fix string.Formatter problem with auto-numbering and
+ nested format_specs. Patch by Anthon van der Neut.
+
- Issue #25233: Rewrite the guts of asyncio.Queue to be more understandable and correct.
- Issue #25203: Failed readline.set_completer_delims() no longer left the