Library to calculate Python functions cognitive complexity via code
Likely abandoned. No release or commit for years (last release over 4 years ago).
Consider insteadcomplexipyPythie’s Index: 842.1M downloads/moCompare →
pip install cognitive-complexitycongnitive-complexity
Library to calculate Python functions cognitive complexity via code.
Installation
pip install cognitive_complexity
Usage
>>> import ast
>>> funcdef = ast.parse("""
... def f(a):
... return a * f(a - 1) # +1 for recursion
... """).body[0]
>>> from cognitive_complexity.api import get_cognitive_complexity
>>> get_cognitive_complexity(funcdef)
1
Flake8-Cognitive-Complexity Extension
Perhaps the most common way to use this library (especially if you are already using the Flake8 linter) is to use the flake8-cognitive-complexity extension. If you run Flake8 with this extension installed, Flake8 will let you know if your code is too complex. For more details and documentation, visit the flake8-cognitive-complexity extension repository.
What is cognitive complexity
Here are some readings about cognitive complexity: