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)

Tested on Python 3.6, 3.7 and flake8 3.7.8.

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:

  • 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

flake8_expression_complexity-0.0.7.tar.gz (5.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: flake8_expression_complexity-0.0.7.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for flake8_expression_complexity-0.0.7.tar.gz
Algorithm Hash digest
SHA256 2378e0235a87c00b4ad7a9759dde1f9c71aebf344f53c9ffa0c2e2c4ee8cd142
MD5 9316a9ba67859856ca3a1cc700f4c1c8
BLAKE2b-256 94022699e1205f1f5e7b13b43e65211b3e4fe157a6ce8668a048a99ff6ef954d

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