Python

Python

Made by DeepSource

Keyword argument defined before variable positional arguments PYL-W1113

Anti-pattern
Major

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]`