{"id":532,"library":"mccabe","title":"McCabe Code Complexity Checker","description":"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.","status":"active","version":"0.7.0","language":"python","source_language":"en","source_url":"https://github.com/pycqa/mccabe","tags":["linter","code quality","complexity","flake8-plugin","static analysis"],"install":[{"cmd":"pip install mccabe flake8","lang":"bash","label":"Install with Flake8"},{"cmd":"pip install mccabe","lang":"bash","label":"Install Standalone"}],"dependencies":[{"reason":"McCabe primarily functions as a plugin for flake8, integrating its complexity checks into the broader linting workflow.","package":"flake8"}],"imports":[{"note":"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.","symbol":"McCabeChecker","correct":"from mccabe import McCabeChecker"}],"quickstart":{"code":"# To analyze a file using mccabe via flake8:\n# 1. Install both libraries\n# pip install mccabe flake8\n\n# 2. Run flake8 with the --max-complexity flag\n# (e.g., to flag functions with complexity > 10)\n# flake8 --max-complexity 10 your_module.py\n\n# Example of a simple Python file to check:\n# your_module.py\ndef high_complexity_function(a, b):\n    if a > 0:\n        if b > 0:\n            print('Both positive')\n        else:\n            print('A positive, B not')\n    elif a < 0:\n        if b < 0:\n            print('Both negative')\n        else:\n            print('A negative, B not')\n    else:\n        print('A is zero')\n\n# To use mccabe as a standalone script (less common):\n# python -m mccabe --min 5 your_module.py","lang":"python","description":"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`."},"warnings":[{"fix":"Ensure your project runs on Python 3.6 or newer when using mccabe 0.7.0 or later.","message":"Version 0.7.0 and later dropped support for Python versions older than 3.6.","severity":"breaking","affected_versions":"0.7.0+"},{"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`.","message":"When used with flake8, the mccabe plugin is disabled by default. You must explicitly enable it by setting the maximum complexity threshold.","severity":"gotcha","affected_versions":"All versions with flake8 integration"},{"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.","message":"To 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.","severity":"gotcha","affected_versions":"All versions with flake8 integration"}],"env_vars":null,"last_verified":"2026-05-12T14:43:21.502Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Refactor the function to reduce its complexity, or explicitly set a higher --max-complexity threshold when running flake8, or add `# noqa: C901` to the line defining the function to ignore the warning for that specific function. For example, `flake8 --max-complexity 10 your_project/`","cause":"The McCabe cyclomatic complexity of the function or method exceeds the configured maximum threshold, indicating potentially overly complex code that might be hard to understand or test.","error":"C901 'function_name' is too complex (X)"},{"fix":"Ensure both `flake8` and `mccabe` are installed and up-to-date (`pip install --upgrade flake8 mccabe`). If the problem persists, try reinstalling them: `pip uninstall flake8 mccabe; pip install flake8 mccabe`.","cause":"This error occurs when the `flake8` command is run with the `--max-complexity` option, but either the `mccabe` plugin is not installed or `flake8` is an older version that does not recognize this option, or `mccabe` is not properly integrated with `flake8`.","error":"flake8: error: no such option: --max-complexity"},{"fix":"Install the `mccabe` package using pip: `pip install mccabe`. If using a virtual environment, ensure it is activated before installation.","cause":"The `mccabe` package is not installed in the Python environment being used, or the Python interpreter cannot find it in its configured paths.","error":"ModuleNotFoundError: No module named 'mccabe'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.1,"disk_size":"17.8M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.1,"disk_size":"19.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.1,"disk_size":"18M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.1,"disk_size":"20M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.1,"disk_size":"19.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.1,"disk_size":"21.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.1,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"11.5M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"13.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":0.8,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":0.8,"disk_size":"14M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"11.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"12.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":0.9,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":0.9,"disk_size":"13M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1,"disk_size":"17.3M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1,"disk_size":"18.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}