An extension for flake8 to report on excessively complex type annotations. Complex type annotations often indicate suboptimal annotation usage, poor code decomposition, or an improper choice of data structure, making the code harder to read. The plugin calculates annotation complexity based on the maximum nesting level (e.g., `List[int]` is 2, `Tuple[List[Optional[str]], int]` is 4). The current version is 0.1.0, and it receives infrequent but active maintenance.
pip install flake8-annotations-complexityNo compatibility data collected yet for this library.
This quickstart demonstrates how to install and use `flake8-annotations-complexity`. It creates a temporary Python file with varying annotation complexities, then runs `flake8` first with the default complexity limit (3) and then with a higher limit (4). The plugin reports errors (TAE002) for annotations exceeding the configured maximum complexity.
Upgrade your project's Python version to 3.9 or later, or pin `flake8-annotations-complexity` to a version prior to 0.1.0.
Configure the `max-annotations-complexity` option in your `flake8` config file (e.g., `setup.cfg` or `pyproject.toml`): `[flake8]\nmax-annotations-complexity = 4`
Consider increasing `--max-annotations-complexity` to accommodate `Annotated` types, or explicitly ignore specific lines/files if the `Annotated` usage is deemed acceptable.
If different complexity thresholds are desired for different contexts, consider using per-file ignores or `noqa` comments to manage specific cases, or look for alternative plugins that offer more granular control.
Run `pip install flake8-annotations-complexity` to install the plugin.
Refactor the complex type annotation using `TypeAlias` (for Python 3.10+) or simpler types, or adjust the maximum allowed complexity with `--max-annotations-complexity=N` in your flake8 command or configuration file.
Ensure `flake8-annotations-complexity` is installed by running `pip install flake8-annotations-complexity`. If it's already installed, verify flake8 can find it by checking `flake8 --version` output for the plugin.
Ensure your configuration file is named correctly (`.flake8`, `setup.cfg`, or `tox.ini`), is located in the project root or an ancestor directory, and contains the `[flake8]` header before any flake8-specific options like `max-annotations-complexity` or `ignore = TAE002`.