flake8-functions

0.0.8 · active · verified Wed Apr 15

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

Install

Quickstart

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.

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

view raw JSON →