Keyword argument before variable positional arguments list in the definition of __init__ function
8class AuthenticationError(ValueError):
9 """A user could not be authenticated."""
10
11 def __init__(self, username=None, msg=None, *args, **kwargs):12 if msg is None:
13 if username:
14 msg = "Authentication failed for user '%s'." % username
Description
On defining a keyword argument before variable positional arguments, one can end up in having multiple values passed for the aforementioned parameter in case the method is called with keyword arguments. It is recommended to define keyword arguments after variable positional arguments.
Bad practice
def create_list(double=False, *args): # first argument will end up in `double`
return list(args)
print(create_list(1, 2, 3)) # prints `[2, 3]`
Recommended
def create_list(*args, double=False):
return list(args)
print(create_list(1, 2, 3)) # prints `[1, 2, 3]`