Library to calculate Python functions cognitive complexity via code
Project description
congnitive-complexity
Library to calculate Python functions cognitive complexity via code.
Installation
pip install cognitive_complexity
Tested on python 3.7 and 3.6.
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
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.
Realization details
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for cognitive_complexity-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c8a237abbbb4ba9e50a3011c0a591e26f7bd6500f029a8b3f01ad81e57b299 |
|
MD5 | a674ab0025b9abaa56b9539bd1259ce2 |
|
BLAKE2b-256 | bdc07ed02b29c19fcfda05a5a8cbdc79cf18e6ae6d3a290c83f43d351abc8a38 |