Skip to content

Waszker/flake-type-annotations-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

flake8 plugin that checks for the correct usage of Python typing annotations

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages