When reading the source code of the string module of python, I am confused by the class Formatter.
The format method (not static nor class method) in the Formatter class does NOT have self as input parameter def format(*args, **kwargs):, but somehow use it directly within the method. self, *args = args.
Please explain this usage.
class Formatter:
def format(*args, **kwargs):
if not args:
raise TypeError("descriptor 'format' of 'Formatter' object "
"needs an argument")
self, *args = args # allow the "self" keyword be passed
try:
format_string, *args = args # allow the "format_string" keyword be passed
except ValueError:
if 'format_string' in kwargs:
...
else:
...
return self.vformat(format_string, args, kwargs)