python/function-too-large
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| Python | warning | none, edit by hand | All versions |
Functions that grow past the fixed 50-statement limit accumulate copy-pasted branches and temporary variables that hide the data flow. Collapse repeated work into loops or data-driven mappings instead of moving statements into helpers.
def summarize(values): # ... more than 50 repeated statements ... return resultdef summarize(values, specs): result = {} for name, fn in specs.items(): result[name] = fn(values) return resultWhat the rule reports
Section titled “What the rule reports”The rule counts executable statements inside each function body (including nested blocks and nested functions, excluding comments and docstrings) against a fixed 50-statement limit.
Existing oversized functions can be recorded at their current statement count alongside the module's total statements under [tool.xpd.ratchet] in pyproject.toml:
[tool.xpd.ratchet."src/pipeline.py"]statements = 420functions = { build_features = 120 }Recorded ceilings may only shrink. Splitting a recorded function into helpers without shrinking the module's total statement count still fails the rule, and raising a ceiling relative to git HEAD fails the rule.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Delete repeated or unnecessary statements by collapsing parallel computations into loops or data-driven mappings, then lower or remove any [tool.xpd.ratchet] entry once the function shrinks.
Diagnostic message
Section titled “Diagnostic message”This function exceeds the fixed 50-statement limit. Collapse repeated work into loops or data-driven mappings instead of moving statements into helpers.See all rules in the Python pack.