-
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
] Improve flexibility of `runtime-evaluated-de…
…corators` (#15204) Co-authored-by: Micha Reiser <micha@reiser.io>
- Loading branch information
1 parent
7ca3f95
commit 1ef0f61
Showing
12 changed files
with
192 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/app.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,25 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import fastapi | ||
from fastapi import FastAPI as Api | ||
|
||
if TYPE_CHECKING: | ||
import datetime # TC004 | ||
from array import array # TC004 | ||
|
||
app = fastapi.FastAPI("First application") | ||
|
||
class AppContainer: | ||
app = Api("Second application") | ||
|
||
app_container = AppContainer() | ||
|
||
@app.put("/datetime") | ||
def set_datetime(value: datetime.datetime): | ||
pass | ||
|
||
@app_container.app.get("/array") | ||
def get_array() -> array: | ||
pass |
14 changes: 14 additions & 0 deletions
14
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/routes.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,14 @@ | ||
from __future__ import annotations | ||
|
||
import pathlib # OK | ||
from datetime import date # OK | ||
|
||
from module.app import app, app_container | ||
|
||
@app.get("/path") | ||
def get_path() -> pathlib.Path: | ||
pass | ||
|
||
@app_container.app.put("/date") | ||
def set_date(d: date): | ||
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
47 changes: 47 additions & 0 deletions
47
...s__flake8_type_checking__tests__runtime-import-in-type-checking-block_module__app.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,47 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
app.py:9:12: TC004 [*] Move import `datetime` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
8 | if TYPE_CHECKING: | ||
9 | import datetime # TC004 | ||
| ^^^^^^^^ TC004 | ||
10 | from array import array # TC004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Unsafe fix | ||
4 4 | | ||
5 5 | import fastapi | ||
6 6 | from fastapi import FastAPI as Api | ||
7 |+import datetime | ||
7 8 | | ||
8 9 | if TYPE_CHECKING: | ||
9 |- import datetime # TC004 | ||
10 10 | from array import array # TC004 | ||
11 11 | | ||
12 12 | app = fastapi.FastAPI("First application") | ||
|
||
app.py:10:23: TC004 [*] Move import `array.array` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
8 | if TYPE_CHECKING: | ||
9 | import datetime # TC004 | ||
10 | from array import array # TC004 | ||
| ^^^^^ TC004 | ||
11 | | ||
12 | app = fastapi.FastAPI("First application") | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Unsafe fix | ||
4 4 | | ||
5 5 | import fastapi | ||
6 6 | from fastapi import FastAPI as Api | ||
7 |+from array import array | ||
7 8 | | ||
8 9 | if TYPE_CHECKING: | ||
9 10 | import datetime # TC004 | ||
10 |- from array import array # TC004 | ||
11 11 | | ||
12 12 | app = fastapi.FastAPI("First application") | ||
13 13 | |
4 changes: 4 additions & 0 deletions
4
...__flake8_type_checking__tests__typing-only-standard-library-import_module__routes.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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.