flake8 plugin for type annotations
Project description
Flake type annotations plugin
The flake8
plugin checking for correct usage of the Python type annotations.
Installation
Plugin requires flake8 >3.0.0
pip install flake-type-annotations-plugin
Rules
ANN001
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 ANN001
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.
ANN002
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 ANN002
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for flake-type-annotations-plugin-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe205ecc46103117e73a33ae4733418acca1e2b14d0994cdb9b17c5ed83a732e |
|
MD5 | c2a12c664db46a18ce643f5ba6b8b327 |
|
BLAKE2b-256 | 9c3c84a0c9be7188d425782c3bad85893c89341a61d8e77dbb26064e63ecb690 |