Skip to content

Adding flake8-future-annotations #3072

@TylerYep

Description

@TylerYep

Hi, I authored the flake8-future-annotations plugin: https://github.com/TylerYep/flake8-future-annotations and I think it would be a good addition to ruff.

The goal of the lint rule is to 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 e.g. typing.List, Dict, Optional, Union, etc.

It pairs especially 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, which I also see is included in ruff.

I plan to take a stab at implementing it (I see many of the necessary components are already tracked in ast.rs) in the following order:

  • Add FA100 (missing future annotations import in Python 3.7+)
  • Add an autofix for FA100 (adds missing future annotations import)
  • Add FA102 (uses simplified types like list or dict but missing future annotations import in Python 3.7 to 3.10)

All feedback is welcome, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    pluginImplementing a known but unsupported plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions