A flake8 extension that checks for type annotations complexity
Maintained. Last release 4 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install flake8-annotations-complexityflake8-annotations-complexity
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:
- 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.