Skip to main content

Library to calculate Python functions cognitive complexity via code

Project description

congnitive-complexity

Build Status Maintainability Test Coverage PyPI version PyPI - Python Version

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

What is cognitive complexity

Here are some readings about cognitive complexity:

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.

Contributing

We would love you to contribute to our project. It's simple:

  • Create an issue with bug you found or proposal you have. Wait for approve from maintainer.
  • Create a pull request. Make sure all checks are green.
  • Fix review comments if any.
  • Be awesome.

Here are useful tips:

  • You can run all checks and tests with make check. Please do it before TravisCI does.
  • We use BestDoctor python styleguide. Sorry, styleguide is available only in Russian for now.
  • We respect Django CoC. Make soft, not bullshit.

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

cognitive_complexity-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file cognitive_complexity-1.0.0.tar.gz.

File metadata

  • Download URL: cognitive_complexity-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.3

File hashes

Hashes for cognitive_complexity-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fa1a2446cac6d7f187ab110181fae1bcc06c26a94f488cdead45ca4775372964
MD5 0042caa31de41ff10470c3bedd30420c
BLAKE2b-256 69d87eca180abcac4ac11cecfe0619e8026b556a8427b89a2e7d74450ce878cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page