-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fix for
future-required-type-annotation
(#8711)
## Summary We already support inserting imports for `I002` -- this PR just adds the same fix for `FA102`, which is explicitly about `from __future__ import annotations`. Closes #8682.
- Loading branch information
1 parent
cd29761
commit a591725
Showing
7 changed files
with
131 additions
and
26 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
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
18 changes: 16 additions & 2 deletions
18
...r__rules__flake8_future_annotations__tests__fa102_no_future_import_uses_lowercase.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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs | ||
--- | ||
no_future_import_uses_lowercase.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
no_future_import_uses_lowercase.py:2:13: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
1 | def main() -> None: | ||
2 | a_list: list[str] = [] | ||
| ^^^^^^^^^ FA102 | ||
3 | a_list.append("hello") | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
no_future_import_uses_lowercase.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_lowercase.py:6:14: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
6 | def hello(y: dict[str, int]) -> None: | ||
| ^^^^^^^^^^^^^^ FA102 | ||
7 | del y | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
|
36 changes: 32 additions & 4 deletions
36
...inter__rules__flake8_future_annotations__tests__fa102_no_future_import_uses_union.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 |
---|---|---|
@@ -1,34 +1,62 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs | ||
--- | ||
no_future_import_uses_union.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
no_future_import_uses_union.py:2:13: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
1 | def main() -> None: | ||
2 | a_list: list[str] | None = [] | ||
| ^^^^^^^^^ FA102 | ||
3 | a_list.append("hello") | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
no_future_import_uses_union.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union | ||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str] | None = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union.py:2:13: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 604 union | ||
| | ||
1 | def main() -> None: | ||
2 | a_list: list[str] | None = [] | ||
| ^^^^^^^^^^^^^^^^ FA102 | ||
3 | a_list.append("hello") | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str] | None = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
no_future_import_uses_union.py:6:14: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
6 | def hello(y: dict[str, int] | None) -> None: | ||
| ^^^^^^^^^^^^^^ FA102 | ||
7 | del y | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
no_future_import_uses_union.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union | ||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str] | None = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union.py:6:14: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 604 union | ||
| | ||
6 | def hello(y: dict[str, int] | None) -> None: | ||
| ^^^^^^^^^^^^^^^^^^^^^ FA102 | ||
7 | del y | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str] | None = [] | ||
3 4 | a_list.append("hello") | ||
|
||
|
54 changes: 48 additions & 6 deletions
54
..._rules__flake8_future_annotations__tests__fa102_no_future_import_uses_union_inner.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 |
---|---|---|
@@ -1,52 +1,94 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs | ||
--- | ||
no_future_import_uses_union_inner.py:2:13: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
no_future_import_uses_union_inner.py:2:13: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
1 | def main() -> None: | ||
2 | a_list: list[str | None] = [] | ||
| ^^^^^^^^^^^^^^^^ FA102 | ||
3 | a_list.append("hello") | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
no_future_import_uses_union_inner.py:2:18: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union | ||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str | None] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union_inner.py:2:18: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 604 union | ||
| | ||
1 | def main() -> None: | ||
2 | a_list: list[str | None] = [] | ||
| ^^^^^^^^^^ FA102 | ||
3 | a_list.append("hello") | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str | None] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union_inner.py:6:14: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
no_future_import_uses_union_inner.py:6:14: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
6 | def hello(y: dict[str | None, int]) -> None: | ||
| ^^^^^^^^^^^^^^^^^^^^^ FA102 | ||
7 | z: tuple[str, str | None, str] = tuple(y) | ||
8 | del z | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str | None] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union_inner.py:6:19: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union | ||
no_future_import_uses_union_inner.py:6:19: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 604 union | ||
| | ||
6 | def hello(y: dict[str | None, int]) -> None: | ||
| ^^^^^^^^^^ FA102 | ||
7 | z: tuple[str, str | None, str] = tuple(y) | ||
8 | del z | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
no_future_import_uses_union_inner.py:7:8: FA102 Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str | None] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union_inner.py:7:8: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| | ||
6 | def hello(y: dict[str | None, int]) -> None: | ||
7 | z: tuple[str, str | None, str] = tuple(y) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FA102 | ||
8 | del z | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str | None] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
no_future_import_uses_union_inner.py:7:19: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union | ||
no_future_import_uses_union_inner.py:7:19: FA102 [*] Missing `from __future__ import annotations`, but uses PEP 604 union | ||
| | ||
6 | def hello(y: dict[str | None, int]) -> None: | ||
7 | z: tuple[str, str | None, str] = tuple(y) | ||
| ^^^^^^^^^^ FA102 | ||
8 | del z | ||
| | ||
= help: Add `from __future__ import annotations` | ||
|
||
ℹ Unsafe fix | ||
1 |+from __future__ import annotations | ||
1 2 | def main() -> None: | ||
2 3 | a_list: list[str | None] = [] | ||
3 4 | a_list.append("hello") | ||
|
||
|
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