Registry / testing / mccabe

mccabe

JSON →
library0.7.0pypypiunverified

McCabe is a Python library that provides a plugin for flake8, the Python code checker. It's used to analyze the cyclomatic complexity (McCabe complexity) of functions and methods in Python code, helping developers identify potentially over-complex code that might be difficult to understand, test, or maintain. The current version is 0.7.0. Its release cadence is slow, often aligning with updates to supported Python versions.

testing
pip install mccabe flake8
Install & Compatibility
Where this runs
tested against v0.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.950 runs
installs and imports cleanly · install 0.0s · import 0.020s · 19.2MB
glibc
py 3.103.950 runs
installs and imports cleanly · install 1.7s · import 0.020s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

McCabeChecker
from mccabe import McCabeChecker
While this is the internal entry point for flake8 to discover the plugin, end-users typically do not import McCabeChecker directly. Its functionality is accessed via the `flake8` command-line tool.

McCabe is most commonly used as a plugin for `flake8`. After installing both `mccabe` and `flake8`, you enable McCabe checks by running `flake8` with the `--max-complexity` option, specifying the threshold at which a warning (C901) should be emitted. Alternatively, it can be run as a standalone script using `python -m mccabe`.

# To analyze a file using mccabe via flake8: # 1. Install both libraries # pip install mccabe flake8 # 2. Run flake8 with the --max-complexity flag # (e.g., to flag functions with complexity > 10) # flake8 --max-complexity 10 your_module.py # Example of a simple Python file to check: # your_module.py def high_complexity_function(a, b): if a > 0: if b > 0: print('Both positive') else: print('A positive, B not') elif a < 0: if b < 0: print('Both negative') else: print('A negative, B not') else: print('A is zero') # To use mccabe as a standalone script (less common): # python -m mccabe --min 5 your_module.py
Debug
Known issues
breakingVersion 0.7.0 and later dropped support for Python versions older than 3.6.
fix
Ensure your project runs on Python 3.6 or newer when using mccabe 0.7.0 or later.
affects: 0.7.0+
gotchaWhen used with flake8, the mccabe plugin is disabled by default. You must explicitly enable it by setting the maximum complexity threshold.
fix
Use the `--max-complexity N` flag when running `flake8` (e.g., `flake8 --max-complexity 10`). Alternatively, configure it in a `setup.cfg`, `.flake8`, or `tox.ini` file under the `[flake8]` section, e.g., `max-complexity = 10`.
affects: All versions with flake8 integration
gotchaTo ignore a specific McCabe complexity violation (C901) for a function, the `# noqa: C901` comment must be placed on the function definition line, not just any line within the function.
fix
Place `# noqa: C901` directly on the line where the `def` keyword or the decorator above it appears for the function you want to ignore.
affects: All versions with flake8 integration
Upgrade
Version history
0.7.0latest on PyPI
Audit
Dependencies
flake8requiredMcCabe primarily functions as a plugin for flake8, integrating its complexity checks into the broader linting workflow.
Agent activity
13 hits · last 30 days
seranking-bot
4
node
2
ahrefsbot
2
bytedance
1
Resources