Skip to main content

Verifies python 3.7+ files use from __future__ import annotations

Project description

flake8-future-annotations

Python 3.7+ PyPI version GitHub license Downloads

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

flake8-future-annotations-0.0.5.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file flake8-future-annotations-0.0.5.tar.gz.

File metadata

File hashes

Hashes for flake8-future-annotations-0.0.5.tar.gz
Algorithm Hash digest
SHA256 da84011070c0d0f623a9c12bd738bea58bc65a3bf5eec20637020069310f8d84
MD5 7c183f713657aada7a1e8dee2fc59e36
BLAKE2b-256 dfe303155473fb46f77388f7c05eb59c888672c1cdf0de84fa5c55481b4d78d9

See more details on using hashes here.

File details

Details for the file flake8_future_annotations-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_future_annotations-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 28fc9ae9e5ece5c211b810d856d984f33c0290933f24ae570731a0751c4917c6
MD5 4a62d6a0ab9fdf2974f9e8453eb85583
BLAKE2b-256 ce8dd65dec7c207aec904b2a1477863d3ab474cc6144037e2632a85cb13de2b8

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