Skip to main content

flake8 plugin for type annotations

Project description

Flake type annotations plugin

Python Version PyPI version PyPI - License Code style: black

The flake8 plugin checking for correct usage of the Python type annotations.

Use with flake8-annotations for even better results!

Installation

Plugin requires flake8 >3.0.0

pip install flake-type-annotations-plugin

Rules

TAN001

This rule disallows usage of Union and Optional type annotations and expects user to use the new | operator syntax.

Example:

# WRONG
from typing import Optional, Union

def func(arg: Optional[int]) -> Union[int, str]:  # violates TAN001
    return arg if arg is not None else "N/A"

# CORRECT
def func(arg: int | None) -> int | str:  # OK
    return arg if arg is not None else "N/A"

For Python versions <3.10 a top-level module import from __future__ import annotations must be included in order to use this syntax.

More can be read in PEP604.

TAN002

This rule disallows usage of type annotations where built-in types can be used.

Example:

# WRONG
from typing import List, Tuple

def func(arg: Tuple[int]) -> List[int]:  # violates TAN002
    return list(arg)

# CORRECT
def func(arg: tuple[int]) -> list[int]:  # OK
    return list(arg)

For Python versions <3.9 a top-level module import from __future__ import annotations must be included in order to use this syntax.

More can be read in PEP585.

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

flake-type-annotations-plugin-0.2.0.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file flake-type-annotations-plugin-0.2.0.tar.gz.

File metadata

File hashes

Hashes for flake-type-annotations-plugin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ff840d48a722e330cb44167a021a7acc9a315b7b1bdb8707db84f9b0d4eb84f6
MD5 fef212e1a9b8b6d3a3f8b03c74a21625
BLAKE2b-256 9a90cd279b5deb4cbe2c7ba1f704ad8829a30c98778bf1f9ed4b5315ccad1106

See more details on using hashes here.

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