flake8-expression-complexity
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:
- 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:
- This project uses uv for dependency management.
Run
make installto 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 installto 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)
| File | Size | Uploaded | |
|---|---|---|---|
| flake8_expression_complexity-0.1.1.tar.gz | 98.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|