Changed signature of string.Formatter.get_field, per suggestion by

Ron Adam.

Added test case for using all parameters in string.Formatter.
This commit is contained in:
Eric Smith 2007-08-31 02:26:31 +00:00
parent 11fe3e05ff
commit 3bcc42ad0f
2 changed files with 27 additions and 7 deletions

View file

@ -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