Skip to main content

flake8-annotations-complexity

Build Status PyPI version PyPI - Python Version

An extension for flake8 to report on too complex type annotations.

Complex type annotations often means bad annotations usage, wrong code decomposition or improper data structure choice. They are also hard to read and make code look java-like.

Annotation complexity is maximum annotation nesting level. So List[int] complexity is 2 and Tuple[List[Optional[str]], int] is 4.

The plugin checks annotations of every argument kind (positional-only, regular, *args, keyword-only and **kwargs), return types of both regular and async functions, and annotated assignments.

Checks

Code Description Option Default
TAE002 Annotation is too complex (nesting level) --max-annotations-complexity 3
TAE003 Annotation is too long (number of elements) --max-annotations-len 7

Requirements

Python 3.10 – 3.14.

Installation

pip install flake8-annotations-complexity

Example

Sample file:

# test.py


def foo() -> List[int]:
    return [1]

Usage:

$ flake8 --max-annotations-complexity=1 test.py
test.py:4:14: TAE002 too complex annotation (2 > 1)

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:

  • The project uses uv. Run make install (or uv sync) to create the environment.
  • Install the git hooks once with uv run pre-commit install.
  • You can run all checks and tests with make check. Please do it before CI does.
  • 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_annotations_complexity-0.2.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

flake8_annotations_complexity-0.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file flake8_annotations_complexity-0.2.0.tar.gz.

File metadata

File hashes

Hashes for flake8_annotations_complexity-0.2.0.tar.gz
Algorithm Hash digest
SHA256 06d3b20aa6048642860b54dfcb74ec786e97a4f65d7548d9ab3f2b77ab60e1ec
MD5 f54314bae34cdc16e307c11329f4bf47
BLAKE2b-256 ac00105bd4fcc95e0b73873bf6cc7eb91f19ba8630953c116b6cababf3fe7543

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_annotations_complexity-0.2.0.tar.gz:

Publisher: publish.yml on best-doctor/flake8-annotations-complexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flake8_annotations_complexity-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_annotations_complexity-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3b86dd5dbbf5eeb5b2ff5c0a68c7dddbcfc0766e057793734b5ccf2a75cf43f
MD5 76039042e10efd21d17247d4e99c2785
BLAKE2b-256 fe298160194a6275c1847ed0f426c79ac01e348d27930db12d6626af15e95905

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_annotations_complexity-0.2.0-py3-none-any.whl:

Publisher: publish.yml on best-doctor/flake8-annotations-complexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page