Verifies python 3.7+ files use from __future__ import annotations
Project description
flake8-future-annotations
Verifies python 3.7+ files use from __future__ import annotations
if a type is used in the module that can be rewritten using PEP 563.
Pairs well with pyupgrade with the --py37-plus
flag or higher, since pyupgrade only replaces type annotations with the PEP 563 rules if from __future__ import annotations
is present.
flake8 codes
Code | Description |
---|---|
FA100 | Missing import if a type used in the module can be rewritten using PEP563 |
FA101 | Missing import when no rewrite using PEP563 is available (see config) |
Example
import typing as t
from typing import List
def function(a_dict: t.Dict[str, t.Optional[int]]) -> None:
a_list: List[str] = []
a_list.append("hello")
As a result, this plugin will emit:
hello.py:1:1: FA100 Missing from __future__ import annotations but imports: List, t.Dict, t.Optional
After adding the future annotations import, running pyupgrade
allows the code to be automatically rewritten as:
from __future__ import annotations
def function(a_dict: dict[str, int | None]) -> None:
a_list: list[str] = []
a_list.append("hello")
Configuration
This plugin has a single configuration which is the --force-future-annotations
option.
If set, missing from __future__ import annotations
will be reported regardless of a rewrite available according to PEP 563; in this case, code FA101 is used instead of FA100.
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
Built Distribution
Hashes for flake8-future-annotations-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cc718f0ffe78db9ecba1e173de386474c2c1de571042c75c02725c49e8122ed |
|
MD5 | 4d52bc33eb746479c7170c98bfdfc57b |
|
BLAKE2b-256 | 12eb55304ab5b07a70fede7196f36387b67cde1d509f31014c8318f16824b7a7 |
Hashes for flake8_future_annotations-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b150d252ee8bf2378f5a055c9ec317378a21f1fb023e98b07f97c336d977e80 |
|
MD5 | 8089d9d36e5a240108cf17793eab8bca |
|
BLAKE2b-256 | e2ca275e6f001d69ecde03b4629ec34c3318c233d7369cdd6dd672ca2e810c87 |