summaryrefslogtreecommitdiffstats
path: root/Lib/string.py
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2007-08-31 02:26:31 (GMT)
committerEric Smith <eric@trueblade.com>2007-08-31 02:26:31 (GMT)
commit3bcc42ad0f18a97ecabb6bb8e645b88d23592a03 (patch)
tree257df068796c27c40c09b93939dd0ea6dc4df6ae /Lib/string.py
parent11fe3e05ff9c8cc4e5a99b8f16f6aee7d39466ef (diff)
downloadcpython-3bcc42ad0f18a97ecabb6bb8e645b88d23592a03.zip
cpython-3bcc42ad0f18a97ecabb6bb8e645b88d23592a03.tar.gz
cpython-3bcc42ad0f18a97ecabb6bb8e645b88d23592a03.tar.bz2
Changed signature of string.Formatter.get_field, per suggestion by
Ron Adam. Added test case for using all parameters in string.Formatter.
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/Lib/string.py b/Lib/string.py
index ad2146c..f60753f 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -208,7 +208,7 @@ class Formatter:
return self.vformat(format_string, args, kwargs)
def vformat(self, format_string, args, kwargs):
- used_args = self.get_empty_used_args()
+ used_args = set()
result = []
for literal_text, field_name, format_spec, conversion in \
self.parse(format_string):
@@ -223,7 +223,9 @@ class Formatter:
# the formatting
# given the field_name, find the object it references
- obj = self.get_field(field_name, args, kwargs, used_args)
+ # and the argument it came from
+ obj, arg_used = self.get_field(field_name, args, kwargs, used_args)
+ used_args.add(arg_used)
# do any conversion on the resulting object
obj = self.convert_field(obj, conversion)
@@ -235,10 +237,6 @@ class Formatter:
return ''.join(result)
- def get_empty_used_args(self):
- return set()
-
-
def get_value(self, key, args, kwargs):
if isinstance(key, int):
return args[key]
@@ -296,4 +294,4 @@ class Formatter:
else:
obj = obj[i]
- return obj
+ return obj, first