flake8-future-annotations


Nameflake8-future-annotations JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/tyleryep/flake8-future-annotations
SummaryVerifies python 3.7+ files use from __future__ import annotations
upload_time2023-01-23 02:05:53
maintainer
docs_urlNone
authorTyler Yep
requires_python>=3.7
licenseMIT
keywords flake8
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flake8-future-annotations

[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![PyPI version](https://badge.fury.io/py/flake8-future-annotations.svg)](https://badge.fury.io/py/flake8-future-annotations)
[![GitHub license](https://img.shields.io/github/license/TylerYep/flake8-future-annotations)](https://github.com/TylerYep/flake8-future-annotations/blob/main/LICENSE)
[![Downloads](https://pepy.tech/badge/flake8-future-annotations)](https://pepy.tech/project/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](https://www.python.org/dev/peps/pep-0563/).

Pairs well with [pyupgrade](https://github.com/asottile/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)     |
| FA102 | Missing import when code uses simplified types (list, dict, set, etc)     |

## Example

```python
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:

```python
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+):

```python
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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tyleryep/flake8-future-annotations",
    "name": "flake8-future-annotations",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "flake8",
    "author": "Tyler Yep",
    "author_email": "tyep@cs.stanford.edu",
    "download_url": "https://files.pythonhosted.org/packages/ce/eb/eee3a350b4c1cae50f9040e78b80b39a3a0d7a5165c5837b68bff00513b3/flake8-future-annotations-1.1.0.tar.gz",
    "platform": null,
    "description": "# flake8-future-annotations\n\n[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)\n[![PyPI version](https://badge.fury.io/py/flake8-future-annotations.svg)](https://badge.fury.io/py/flake8-future-annotations)\n[![GitHub license](https://img.shields.io/github/license/TylerYep/flake8-future-annotations)](https://github.com/TylerYep/flake8-future-annotations/blob/main/LICENSE)\n[![Downloads](https://pepy.tech/badge/flake8-future-annotations)](https://pepy.tech/project/flake8-future-annotations)\n\nVerifies python 3.7+ files use `from __future__ import annotations` if a type is used in the module that can be rewritten using [PEP 563](https://www.python.org/dev/peps/pep-0563/).\n\nPairs well with [pyupgrade](https://github.com/asottile/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.\n\n## flake8 codes\n\n| Code  | Description                                                               |\n| ----- | ------------------------------------------------------------------------- |\n| FA100 | Missing import if a type used in the module can be rewritten using PEP563 |\n| FA101 | Missing import when no rewrite using PEP563 is available (see config)     |\n| FA102 | Missing import when code uses simplified types (list, dict, set, etc)     |\n\n## Example\n\n```python\nimport typing as t\nfrom typing import List\n\ndef function(a_dict: t.Dict[str, t.Optional[int]]) -> None:\n    a_list: List[str] = []\n    a_list.append(\"hello\")\n```\n\nAs a result, this plugin will emit:\n\n```\nhello.py:1:1: FA100 Missing from __future__ import annotations but imports: List, t.Dict, t.Optional\n```\n\nAfter adding the future annotations import, running `pyupgrade` allows the code to be automatically rewritten as:\n\n```python\nfrom __future__ import annotations\n\ndef function(a_dict: dict[str, int | None]) -> None:\n    a_list: list[str] = []\n    a_list.append(\"hello\")\n```\n\n## Configuration\n\nIf 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.\n\nIf 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+):\n\n```python\ndef function(a_dict: dict[str, int | None]) -> None:\n    a_list: list[str] = []\n    a_list.append(\"hello\")\n```\n\n```\nhello.py:1:1: FA102 Missing from __future__ import annotations but uses simplified type annotations: dict, list, union\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Verifies python 3.7+ files use from __future__ import annotations",
    "version": "1.1.0",
    "split_keywords": [
        "flake8"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45e4e3e6f788d9d5b5ff9a5fe2ceb6aaff9dea248aaa24c0217866c65fa5d0bf",
                "md5": "38abc98630f34d96e5e79d20034fc360",
                "sha256": "555f16f51ae24ab4d0683b1ce8d0f59d36259c3a7e776bd5642f58c78ce7d3ab"
            },
            "downloads": -1,
            "filename": "flake8_future_annotations-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "38abc98630f34d96e5e79d20034fc360",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10408,
            "upload_time": "2023-01-23T02:05:51",
            "upload_time_iso_8601": "2023-01-23T02:05:51.384271Z",
            "url": "https://files.pythonhosted.org/packages/45/e4/e3e6f788d9d5b5ff9a5fe2ceb6aaff9dea248aaa24c0217866c65fa5d0bf/flake8_future_annotations-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ceebeee3a350b4c1cae50f9040e78b80b39a3a0d7a5165c5837b68bff00513b3",
                "md5": "ed3c8f57ec74601c090dff6e2d9c40ab",
                "sha256": "df416bd2b9e1eda7ea639a5fd2a083dabb942ffe49d197f836df380d0dcf6608"
            },
            "downloads": -1,
            "filename": "flake8-future-annotations-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ed3c8f57ec74601c090dff6e2d9c40ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6832,
            "upload_time": "2023-01-23T02:05:53",
            "upload_time_iso_8601": "2023-01-23T02:05:53.949491Z",
            "url": "https://files.pythonhosted.org/packages/ce/eb/eee3a350b4c1cae50f9040e78b80b39a3a0d7a5165c5837b68bff00513b3/flake8-future-annotations-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-23 02:05:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "tyleryep",
    "github_project": "flake8-future-annotations",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flake8-future-annotations"
}
        
Elapsed time: 0.03282s