Skip to content

Detector: Complexity

Jacob Centner edited this page Apr 10, 2026 · 1 revision

Detector: Complexity

Flags Python functions that exceed cyclomatic complexity or line-count thresholds.

Property Value
Name complexity
Tier HEURISTIC
Languages Python
External tool None (uses Python ast)
LLM required No
Confidence 0.95 (source), 0.60 (test files)

What it detects

Python functions with:

  • Cyclomatic complexity > 10 (decision points: if, elif, for, while, except, and, or, assert, ternary)
  • Body longer than 50 lines

How it works

  1. Parses Python files with the ast module
  2. Walks all FunctionDef and AsyncFunctionDef nodes
  3. Calculates McCabe cyclomatic complexity and body line count
  4. Flags functions exceeding either threshold

Severity

Condition Severity
CC > 20 or lines > 150 HIGH
CC > 15 or lines > 100 MEDIUM
Above threshold LOW

Test files (test_*.py, files under tests/) are always demoted to LOW severity with 0.60 confidence — complex tests are common and rarely worth refactoring.

Example finding

[COMPLEXITY] src/httpx/_multipart.py:DataField.render_headers
  Complex function: render_headers (cyclomatic complexity 14, 62 lines)
  Severity: MEDIUM, Confidence: 0.95

Observed accuracy

Repo Findings Notes
pip-tools 20 ~100% TP, some in tests
httpx 31 ~95% TP, ~15 in test files

Known limitations

  • Python-only (no JS/TS, Go, or Rust complexity analysis)
  • Thresholds are not yet configurable via sentinel.toml
  • Test files produce accurate but low-value findings (severity demoted to mitigate)

Clone this wiki locally