Library to calculate Python functions cognitive complexity via code
Library to calculate Python functions cognitive complexity via code.
pip install cognitive_complexity
Tested on python 3.7 and 3.6.
>>> import ast >>> funcdef = ast.parse(""" ... def f(a): ... return a * f(a - 1) # +1 for recursion ... """).body >>> from cognitive_complexity.api import get_cognitive_complexity >>> get_cognitive_complexity(funcdef) 1
What is cognitive complexity
Here are some readings about cognitive complexity:
- Cognitive Complexity, Because Testability != Understandability;
- Cognitive Complexity: A new way of measuring understandability, white paper by G. Ann Campbell;
- Cognitive Complexity: the New Guide to Refactoring for Maintainable Code;
- Cognitive Complexity from CodeClimate docs;
- Is Your Code Readable By Humans? Cognitive Complexity Tells You.
This is not precise realization of original algorithm proposed by G. Ann Campbell, but it gives rather similar results. The algorithm gives complexity points for breaking control flow, nesting, recursion, stacks logic operation etc.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size cognitive_complexity-0.0.4.tar.gz (3.3 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for cognitive_complexity-0.0.4.tar.gz