Skip to main content

flake8-expression-complexity

Build Status 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

Requires Python 3.10 to 3.14.

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:

  • This project uses uv for dependency management. Run make install to set up a local environment.
  • You can run all checks and tests with make check. Please do it before CI does.
  • Install the pre-commit hooks with uv run pre-commit install to catch issues before you commit.
  • We use BestDoctor python styleguide.
  • We respect Django CoC. Make soft, not bullshit.

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.1.1.tar.gz (98.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_expression_complexity-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for flake8_expression_complexity-0.1.1.tar.gz
Algorithm Hash digest
SHA256 687ced3b58b5e5a1db814575fcb71f7457cfe865f820e57144a6c3c13382aa6b
MD5 e12b72b6eb936dadf56fc94c5ab748f4
BLAKE2b-256 e49951bc08a56ed84c21a3652b9631ff390a413d81dcff0451c04dbe34f2c0ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flake8_expression_complexity-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b58134c01e4619eda2d337cd934077db3fa20eb75b4df4cf2e44fc4f3be5743
MD5 91370a830f83df6e4c2b59e6476d324f
BLAKE2b-256 78a2f5de0bb7bb2679df7067822c1605f29ed95ef62f351f0d804fa9c974ef02

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page