-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-type-checking
] Add exemption for runtime evaluated decorato…
…r classes
- Loading branch information
Showing
14 changed files
with
351 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ter/resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorator_classes_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import fastapi | ||
from fastapi import FastAPI as Api | ||
|
||
from example import DecoratingClass | ||
|
||
if TYPE_CHECKING: | ||
import datetime # TC004 | ||
from array import array # TC004 | ||
|
||
import pathlib # TC004 | ||
|
||
import pyproj | ||
|
||
app1 = fastapi.FastAPI("First application") | ||
app2 = Api("Second application") | ||
|
||
decorating_instance = DecoratingClass() | ||
|
||
@app1.put("/datetime") | ||
def set_datetime(value: datetime.datetime): | ||
pass | ||
|
||
@app2.get("/array") | ||
def get_array() -> array: | ||
pass | ||
|
||
@decorating_instance.decorator | ||
def foo(path: pathlib.Path) -> None: | ||
pass | ||
|
||
@decorating_instance | ||
def bar(arg: pyproj.Transformer) -> None: | ||
pass | ||
|
||
@DecoratingClass | ||
def baz(arg: pyproj.Transformer) -> None: | ||
pass |
32 changes: 32 additions & 0 deletions
32
...ter/resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorator_classes_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import pandas | ||
import pyproj | ||
|
||
import fastapi | ||
from fastapi import FastAPI as Api | ||
from example import DecoratingClass | ||
|
||
import numpy # TC002 | ||
|
||
app1 = fastapi.FastAPI("First application") | ||
app2 = Api("Second application") | ||
|
||
decorating_instance = DecoratingClass() | ||
|
||
|
||
@app1.get("/transformer") | ||
def get_transformer() -> pyproj.Transformer: | ||
pass | ||
|
||
@app2.put("/dataframe") | ||
def set_dataframe(df: pandas.DataFrame): | ||
pass | ||
|
||
@decorating_instance | ||
def foo(x: pandas.DataFrame): | ||
pass | ||
|
||
@DecoratingClass | ||
def bar(x: numpy.ndarray): | ||
pass |
31 changes: 31 additions & 0 deletions
31
...ter/resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorator_classes_3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
import pathlib | ||
|
||
import fastapi | ||
from fastapi import FastAPI as Api | ||
from example import DecoratingClass | ||
|
||
from uuid import UUID # TC003 | ||
|
||
app1 = fastapi.FastAPI("First application") | ||
app2 = Api("Second application") | ||
|
||
decorating_instance = DecoratingClass() | ||
|
||
|
||
@app1.get("/path") | ||
def get_path() -> pathlib.Path: | ||
pass | ||
|
||
@app2.put("/pure_path") | ||
def set_pure_path(df: pathlib.PurePath): | ||
pass | ||
|
||
@decorating_instance | ||
def foo(x: pathlib.PosixPath): | ||
pass | ||
|
||
@DecoratingClass | ||
def bar(x: UUID): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ests__runtime-import-in-type-checking-block_runtime_evaluated_decorator_classes_1.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
snapshot_kind: text | ||
--- | ||
runtime_evaluated_decorator_classes_1.py:11:12: TC004 [*] Move import `datetime` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
10 | if TYPE_CHECKING: | ||
11 | import datetime # TC004 | ||
| ^^^^^^^^ TC004 | ||
12 | from array import array # TC004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Unsafe fix | ||
6 6 | from fastapi import FastAPI as Api | ||
7 7 | | ||
8 8 | from example import DecoratingClass | ||
9 |+import datetime | ||
9 10 | | ||
10 11 | if TYPE_CHECKING: | ||
11 |- import datetime # TC004 | ||
12 12 | from array import array # TC004 | ||
13 13 | | ||
14 14 | import pathlib # TC004 | ||
|
||
runtime_evaluated_decorator_classes_1.py:12:23: TC004 [*] Move import `array.array` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
10 | if TYPE_CHECKING: | ||
11 | import datetime # TC004 | ||
12 | from array import array # TC004 | ||
| ^^^^^ TC004 | ||
13 | | ||
14 | import pathlib # TC004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Unsafe fix | ||
6 6 | from fastapi import FastAPI as Api | ||
7 7 | | ||
8 8 | from example import DecoratingClass | ||
9 |+from array import array | ||
9 10 | | ||
10 11 | if TYPE_CHECKING: | ||
11 12 | import datetime # TC004 | ||
12 |- from array import array # TC004 | ||
13 13 | | ||
14 14 | import pathlib # TC004 | ||
15 15 | | ||
|
||
runtime_evaluated_decorator_classes_1.py:14:12: TC004 [*] Move import `pathlib` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
12 | from array import array # TC004 | ||
13 | | ||
14 | import pathlib # TC004 | ||
| ^^^^^^^ TC004 | ||
15 | | ||
16 | import pyproj | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Unsafe fix | ||
6 6 | from fastapi import FastAPI as Api | ||
7 7 | | ||
8 8 | from example import DecoratingClass | ||
9 |+import pathlib | ||
9 10 | | ||
10 11 | if TYPE_CHECKING: | ||
11 12 | import datetime # TC004 | ||
12 13 | from array import array # TC004 | ||
13 14 | | ||
14 |- import pathlib # TC004 | ||
15 15 | | ||
16 16 | import pyproj | ||
17 17 | |
Oops, something went wrong.