Skip to main content

A flake8 extension that checks expressions complexity

Project description

flake8-expression-complexity

Build Status Maintainability Test Coverage PyPI version PyPI - Python Version

An extension for flake8 that validates expression complexity.

Splits code into expression and scores each according to how much one is complicated. Fires an error on each expression more complex than theshold.

Default complexity is 7, can be configured via --max-expression-complexity option.

Since Django ORM queries can produce long and readable expressions, checker can skip them. To enable this behaviour, use --ignore-django-orm-queries-complexity option.

Installation

pip install flake8-expression-complexity

Example

if (
    (user and user.is_authorized)
    and user.subscriptions.filter(start_date__lt=today, end_date__gt=today).exists()
    and (
        user.total_credits_added
        - Check.objects.filter(user=user).aggregate(Sum('price'))['check__sum']
    )
    and UserAction.objects.filter(user=user).last().datetime > today - datetime.timedelta(days=10)
):
    ...

Usage:

$ flake8 --max-expression-complexity=3 test.py
text.py:2:5: ECE001 Expression is too complex (7.0 > 3)

Error codes

Error code Description
ECE001 Expression is too complex (X > Y)

Contributing

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

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

Here are useful tips:

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

flake8_expression_complexity-0.0.11.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file flake8_expression_complexity-0.0.11.tar.gz.

File metadata

  • Download URL: flake8_expression_complexity-0.0.11.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for flake8_expression_complexity-0.0.11.tar.gz
Algorithm Hash digest
SHA256 4dd8909fecbc20f53814cdcef9d0b04f61532764278d9b6e8026686812e96631
MD5 f621be803c47473db0f1cfc0bd6599fe
BLAKE2b-256 19715bfb69acbfd319add958c70b60e68aee8914d4a5e243b87f4fcda249cf7b

See more details on using hashes here.

File details

Details for the file flake8_expression_complexity-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: flake8_expression_complexity-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for flake8_expression_complexity-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 b56bac37f7dd5d3d102a7111c89f6579c2cbd897b868147794c9ed12aadc627c
MD5 b806a6ba0bb47ad3c44bcf7e96a90eb7
BLAKE2b-256 bc206707c990610d45a3a961345ad5fdabf096cac5a1ce8571581f5787453574

See more details on using hashes here.

Supported by

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