Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flake8-future-annotations

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flake8-future-annotations

Verifies python 3.7+ files use from __future__ import annotations

  • 1.1.0
  • PyPI
  • Socket score

Maintainers
1

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

CodeDescription
FA100Missing import if a type used in the module can be rewritten using PEP563
FA101Missing import when no rewrite using PEP563 is available (see config)
FA102Missing import when code uses simplified types (list, dict, set, etc)

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

If the --force-future-annotations option is 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.

If the --check-future-annotations option is set, missing from __future__ import annotations will be reported because the following code will error on Python versions older than 3.10 (this check does not output anything for versions 3.10+):

def function(a_dict: dict[str, int | None]) -> None:
    a_list: list[str] = []
    a_list.append("hello")
hello.py:1:1: FA102 Missing from __future__ import annotations but uses simplified type annotations: dict, list, union

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc