Skip to main content

Flake8 Type Annotation Checks

Project description

flake8-annotations

PyPI - Python Version PyPI Build Status Discord

flake8-annotations is a plugin for Flake8 that detects the absence of PEP 3107-style function annotations.

What this won't do: Check variable annotations (see: PEP 526), check type comments (see: PEP 484), or replace mypy's compile-time type checking.

Installation

Install from PyPi with your favorite pip invocation:

$ pip install flake8-annotations

It will then be run automatically as part of Flake8.

You can verify it's being picked up by invoking the following in your shell:

$ flake8 --version
3.7.8 (flake8-annotations: 1.0.0, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.4 on Darwin

Table of Warnings

Function Annotations

ID Description
TYP001 Missing type annotation for function argument
TYP002 Missing type annotation for *args
TYP003 Missing type annotation for **kwargs

Method Annotations

ID Description
TYP101 Missing type annotation for self in method
TYP102 Missing type annotation for cls in classmethod

Return Annotations

ID Description
TYP201 Missing return type annotation for public function
TYP202 Missing return type annotation for protected function
TYP203 Missing return type annotation for secret function
TYP204 Missing return type annotation for special method
TYP205 Missing return type annotation for staticmethod
TYP206 Missing return type annotation for classmethod

Contributing

Please take some time to read through our contributing guidelines before helping us with this project.

Development Environment

This project uses Pipenv to manage dependencies. With your fork cloned to your local machine, you can create a developer environment using:

$ pipenv sync --dev

Note: flake8-annotations is included in the Pipfile as an editable dependency so it will be included when flake8 is invoked in your developer environment.

A pre-commit installation script and configuration is also provided to create a pre-commit hook so linting errors aren't committed:

$ pipenv run precommit

Testing

A pytest suite is provided for testing:

$ pipenv run test

Coverage

Test coverage is provided by pytest-cov via a pipenv script:

$ pipenv run coverage

When running via pipenv, details on missing coverage is provided in the report to allow the user to generate additional tests for full coverage.

e.g.

----------- coverage: platform win32, python 3.7.4-final-0 -----------
Name                                Stmts   Miss  Cover   Missing
-----------------------------------------------------------------
flake8_annotations\__init__.py        110      1    99%   164
flake8_annotations\checker.py          57      0   100%
flake8_annotations\enums.py            15      0   100%
flake8_annotations\error_codes.py      85      0   100%
-----------------------------------------------------------------
TOTAL                                 267      1    99%

Project details


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-1.0.0.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

flake8_annotations-1.0.0-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page