too-many-positional-arguments / R0917ΒΆ
Message emitted:
Too many positional arguments (%s/%s)
Description:
Used when a function has too many positional arguments.
Problematic code:
class FiveArgumentMethods:
"""The max positional arguments default is 5."""
def take_five_args(self, a, b, c, d, e): # [too-many-positional-arguments]
pass
Correct code:
class FiveArgumentMethods:
"""The max positional arguments default is 5."""
def take_five_args(self, a, b, c, d, *, e=False):
pass
Configuration file:
[MESSAGES CONTROL]
disable=too-many-arguments
Additional details:
Positional arguments work well for cases where the the use cases are
self-evident, such as unittest's assertEqual(first, second, msg=None)
.
Comprehensibility suffers beyond a handful of arguments, though, so for
functions that take more inputs, require that additional arguments be
passed by keyword only by preceding them with *
:
def make_noise(self, volume, *, color=noise.PINK, debug=True):
...
Related links:
Created by the design checker.