Skip to main content

flake8-adjustable-complexity

Build Status Maintainability Test Coverage

An extension for flake8 to report on too complex functions with bad variables names.

Sometimes you want to use too generic variable name inside some function. It this case you want to be sure that the function is more simple that others, so a reader doesn't have to remember meaning of a variable together with other logic for a long time.

This plugin calculates max allowed cyclomatic complexity for each function separately. Default is 7, and it is decreased by 2 for each variable from blacklist inside the function. If actual complexity overcomes max calculated complexity, the plugin reports an error.

Currently, the following errors are reported:

Code Description
CAC001 func is too complex (complexity > max allowed complexity)
CAC002 func is too complex (complexity). Bad variable names penalty is too high (penalty)

Installation

pip install flake8-adjustable-complexity

Configuration

The plugin has the following configuration options:

  • --max-mccabe-complexity (or --max-adjustable-complexity) - Max allowed cyclomatic complexity.
  • --per-path-max-adjustable-complexity - Per-path complexity settings. The value of the option must be a comma-separated list of <path>:<complexity> pairs.
  • --var-names-extra-blacklist - Comma-separated list of bad variable names to blacklist. Each variable will affect the max allowed complexity.
  • --var-names-whitelist - Comma-separated list of bad variable names to whitelist.

All options also can be specified via [flake8] section of setup.cfg.

Example

Sample file:

# test.py

def foo():
    for vars in range(5):
        for info in range(5):
            for obj in range(5):
                pass

Usage:

$ flake8 test.py
test.py:1:1: CAC001 foo is too complex (4 > 1)

Contributing

We would love you to contribute to our project. It's simple:

  1. Create an issue with bug you found or proposal you have. Wait for approve from maintainer.
  2. Create a pull request. Make sure all checks are green.
  3. Fix review comments if any.
  4. Be awesome.

Here are useful tips:

Release files for flake8-adjustable-complexity 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-adjustable-complexity 0.0.6
File Size Uploaded
flake8_adjustable_complexity-0.0.6.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-adjustable-complexity 0.0.6
File Interpreter ABI Platform
flake8_adjustable_complexity-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / flake8_adjustable_complexity-0.0.6.tar.gz

Download URL flake8_adjustable_complexity-0.0.6.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3a0adc2a957370cf8878fc255b111244b77ae48f9944fc67db6935388dbd1b15
BLAKE2b-256 checksum
How to use checksums
6f92f1083e663117a47acb88034f9cbbb955398c5edebd9c8500c87e96cd06b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / flake8_adjustable_complexity-0.0.6-py3-none-any.whl

Download URL flake8_adjustable_complexity-0.0.6-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c84d22aba91b6ccea2cd9d240f76e1cc973232322e64d89f07d803fcd547042
BLAKE2b-256 checksum
How to use checksums
defa3f5515b7a05edfdbb0555354867962a04a58d236421a8cf61e13bf622d38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page