flake8-functions
flake8-functions is a Flake8 extension that checks for issues related to Python functions, such as excessive length, too many arguments, purity, and number of return statements. It provides specific error codes like CFQ001, CFQ002, CFQ003, and CFQ004. The current version is 0.0.8, released on April 10, 2023. This is an actively maintained project with releases as needed to address issues and enhance checks.
Warnings
- gotcha Flake8 plugins are automatically activated upon installation. There are no direct Python imports required or exposed for `flake8-functions` within your code. Simply `pip install flake8-functions` and `flake8` will pick it up.
- gotcha The default limits for checks (e.g., maximum function length, number of arguments, number of returns) might not align with every project's style guide. For instance, the default `max-function-length` is 100 lines.
- gotcha The definition of 'pure function' (CFQ003 check) implemented by `flake8-functions` might have specific interpretations or limitations, potentially leading to false positives or negatives depending on your project's context or Python version nuances. The documentation does not extensively detail its exact purity detection logic.
- gotcha While `flake8-functions` explicitly supports Python 3.7+ (and PyPI lists 3.6-3.10), `flake8` itself has evolving Python version requirements. Newer versions of `flake8` (e.g., `flake8` 7.2.0 requires Python >= 3.9) might implicitly make `flake8-functions` incompatible with older Python versions if your `flake8` dependency is not pinned.
Install
-
pip install flake8 flake8-functions
Quickstart
import os
def some_long_function(first_parameter, second_parameter, third_parameter):
# This function is intentionally long to trigger CFQ001
result = first_parameter + second_parameter
result = result * third_parameter
result = result / (first_parameter + 1)
result = result % second_parameter
result = result ** 2
result = result + first_parameter + second_parameter + third_parameter
result = result * 5 - 10
result = result + 100 / (second_parameter - 1)
result = result - (third_parameter * first_parameter)
result = result * (first_parameter + second_parameter + third_parameter)
return first_parameter
def short_function():
return 1
# Save this code to a file named 'example.py'
# Then run: flake8 --max-function-length=10 example.py