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.
pip install flake8 flake8-functionsNo compatibility data collected yet for this library.
Install flake8 and flake8-functions, then run flake8 on a Python file. flake8-functions checks are automatically integrated. The example shows a function that exceeds a configured maximum length (CFQ001). To trigger this, a `max-function-length` is specified on the command line, or can be configured in a `.flake8` or `setup.cfg` file.
Ensure `flake8-functions` is installed in the same environment as `flake8`. Run `flake8` command as usual; no extra configuration is needed for activation.
Configure `flake8-functions` settings in a `.flake8` or `setup.cfg` file in your project root, or via command-line flags. For example, to change max function length: `[flake8] max-function-length = 50` or `flake8 --max-function-length=50`.
Review the source code for the CFQ003 check if specific functions are unexpectedly flagged or missed. If the check is too strict or not suitable, it can be disabled using `--ignore=CFQ003` in your `flake8` configuration.
Always use a Python version compatible with both `flake8-functions` and your chosen version of `flake8`. It's recommended to use Python 3.9+ for modern `flake8` setups. Pin `flake8` and `flake8-functions` versions in your `requirements.txt` or `pyproject.toml` to ensure consistent behavior.
Refactor the function to be shorter, or increase the `max-function-length` setting in your Flake8 configuration (e.g., `setup.cfg` or `pyproject.toml`). To ignore a specific instance, add `# noqa: CFQ001` to the function definition line.
Reduce the number of arguments (e.g., by passing an object or using `*args`/`**kwargs` carefully), or increase the `max-arguments-amount` setting in your Flake8 configuration. To ignore a specific instance, add `# noqa: CFQ002` to the function definition line.
Refactor the function to avoid side-effects, making its output solely dependent on its inputs. If the side-effect is intentional and desired, ignore the error by adding `# noqa: CFQ003` to the function definition line.
Refactor the function to reduce the number of return paths (e.g., consolidate logic or use early exits more strategically), or increase the `max-returns-amount` setting in your Flake8 configuration. To ignore a specific instance, add `# noqa: CFQ004` to the function definition line.