@@ -169,7 +169,8 @@ def vformat(self, format_string, args, kwargs):
169169 self .check_unused_args (used_args , args , kwargs )
170170 return result
171171
172- def _vformat (self , format_string , args , kwargs , used_args , recursion_depth ):
172+ def _vformat (self , format_string , args , kwargs , used_args , recursion_depth ,
173+ auto_arg_index = 0 ):
173174 if recursion_depth < 0 :
174175 raise ValueError ('Max string recursion exceeded' )
175176 result = []
@@ -185,6 +186,23 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth):
185186 # this is some markup, find the object and do
186187 # the formatting
187188
189+ # handle arg indexing when empty field_names are given.
190+ if field_name == '' :
191+ if auto_arg_index is False :
192+ raise ValueError ('cannot switch from manual field '
193+ 'specification to automatic field '
194+ 'numbering' )
195+ field_name = str (auto_arg_index )
196+ auto_arg_index += 1
197+ elif field_name .isdigit ():
198+ if auto_arg_index :
199+ raise ValueError ('cannot switch from manual field '
200+ 'specification to automatic field '
201+ 'numbering' )
202+ # disable auto arg incrementing, if it gets
203+ # used later on, then an exception will be raised
204+ auto_arg_index = False
205+
188206 # given the field_name, find the object it references
189207 # and the argument it came from
190208 obj , arg_used = self .get_field (field_name , args , kwargs )
@@ -195,7 +213,8 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth):
195213
196214 # expand the format spec, if needed
197215 format_spec = self ._vformat (format_spec , args , kwargs ,
198- used_args , recursion_depth - 1 )
216+ used_args , recursion_depth - 1 ,
217+ auto_arg_index = auto_arg_index )
199218
200219 # format the object and append to the result
201220 result .append (self .format_field (obj , format_spec ))
0 commit comments