@@ -94,7 +94,11 @@ def _invalid(self, mo):
9494 raise ValueError ('Invalid placeholder in string: line %d, col %d' %
9595 (lineno , colno ))
9696
97- def substitute (self , * args , ** kws ):
97+ def substitute (* args , ** kws ):
98+ if not args :
99+ raise TypeError ("descriptor 'substitute' of 'Template' object "
100+ "needs an argument" )
101+ self , * args = args # allow the "self" keyword be passed
98102 if len (args ) > 1 :
99103 raise TypeError ('Too many positional arguments' )
100104 if not args :
@@ -120,7 +124,11 @@ def convert(mo):
120124 self .pattern )
121125 return self .pattern .sub (convert , self .template )
122126
123- def safe_substitute (self , * args , ** kws ):
127+ def safe_substitute (* args , ** kws ):
128+ if not args :
129+ raise TypeError ("descriptor 'safe_substitute' of 'Template' object "
130+ "needs an argument" )
131+ self , * args = args # allow the "self" keyword be passed
124132 if len (args ) > 1 :
125133 raise TypeError ('Too many positional arguments' )
126134 if not args :
@@ -160,7 +168,19 @@ def convert(mo):
160168# The field name parser is implemented in _string.formatter_field_name_split
161169
162170class Formatter :
163- def format (self , format_string , * args , ** kwargs ):
171+ def format (* args , ** kwargs ):
172+ if not args :
173+ raise TypeError ("descriptor 'format' of 'Formatter' object "
174+ "needs an argument" )
175+ self , * args = args # allow the "self" keyword be passed
176+ try :
177+ format_string , * args = args # allow the "format_string" keyword be passed
178+ except ValueError :
179+ if 'format_string' in kwargs :
180+ format_string = kwargs .pop ('format_string' )
181+ else :
182+ raise TypeError ("format() missing 1 required positional "
183+ "argument: 'format_string'" ) from None
164184 return self .vformat (format_string , args , kwargs )
165185
166186 def vformat (self , format_string , args , kwargs ):
0 commit comments