Max Parameters
ID |
python.max_params |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Complexity |
Language |
Python |
Tags |
complexity |
Description
Reports a function or method whose parameter count exceeds a configurable threshold (default 7). High parameter counts are hard to call correctly, hard to remember the order of, and almost always indicate the function has accumulated unrelated responsibilities.
The implicit self / cls parameter on instance / class methods is not counted. args / *kwargs each count as one. The bare * keyword-only separator is not a parameter.
def process(a, b, c, d, e, f, g, h): # FLAW with default maxParams=7
...
class Worker:
def run(self, a, b, c, d, e, f, g, h): # FLAW — self excluded, 8 caller params
...
def process(opts): # OK — single options object
...
Rationale
Long parameter lists are call-site noise, an indicator of mixed responsibilities, and a common source of off-by-one bugs from accidentally swapped positional arguments.
Remediation
-
Bundle related parameters into a dataclass / NamedTuple / TypedDict.
-
Split the function — large parameter lists almost always reflect more than one job.
-
Use keyword-only parameters (
def f(*, a, b, c)) to make the call site self-documenting.