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.

Release files for flake8-expression-complexity 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-expression-complexity 0.1.1
File Size Uploaded
flake8_expression_complexity-0.1.1.tar.gz 98.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-expression-complexity 0.1.1
File Interpreter ABI Platform
flake8_expression_complexity-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 106.5 kB

Release files / flake8_expression_complexity-0.1.1.tar.gz

Download URL flake8_expression_complexity-0.1.1.tar.gz
Size 98.4 kB
Tags Source
SHA-256 checksum
How to use checksums
687ced3b58b5e5a1db814575fcb71f7457cfe865f820e57144a6c3c13382aa6b
BLAKE2b-256 checksum
How to use checksums
e49951bc08a56ed84c21a3652b9631ff390a413d81dcff0451c04dbe34f2c0ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / flake8_expression_complexity-0.1.1-py3-none-any.whl

Download URL flake8_expression_complexity-0.1.1-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b58134c01e4619eda2d337cd934077db3fa20eb75b4df4cf2e44fc4f3be5743
BLAKE2b-256 checksum
How to use checksums
78a2f5de0bb7bb2679df7067822c1605f29ed95ef62f351f0d804fa9c974ef02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release 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