forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include alias when formatting import-from structs (astral-sh#5786)
## Summary When required-imports is set with the syntax from ... import ... as ..., autofix I002 is failing ## Test Plan Reuse the same python files as `crates/ruff/src/rules/isort/mod.rs:required_import` test.
- Loading branch information
1 parent
1777683
commit 7d4b9e4
Showing
12 changed files
with
171 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
...les/isort/snapshots/ruff__rules__isort__tests__required_import_with_alias_comment.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,19 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
comment.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | #!/usr/bin/env python3 | ||
| I002 | ||
2 | | ||
3 | x = 1 | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 1 | #!/usr/bin/env python3 | ||
2 |+from __future__ import annotations as _annotations | ||
2 3 | | ||
3 4 | x = 1 | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
...s/isort/snapshots/ruff__rules__isort__tests__required_import_with_alias_docstring.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,19 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
docstring.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | """Hello, world!""" | ||
| I002 | ||
2 | | ||
3 | x = 1 | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 1 | """Hello, world!""" | ||
2 |+from __future__ import annotations as _annotations | ||
2 3 | | ||
3 4 | x = 1 | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
.../isort/snapshots/ruff__rules__isort__tests__required_import_with_alias_docstring.pyi.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/src/rules/isort/mod.rs | ||
--- | ||
|
4 changes: 4 additions & 0 deletions
4
...rt/snapshots/ruff__rules__isort__tests__required_import_with_alias_docstring_only.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/src/rules/isort/mod.rs | ||
--- | ||
|
17 changes: 17 additions & 0 deletions
17
...ruff__rules__isort__tests__required_import_with_alias_docstring_with_continuation.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,17 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
docstring_with_continuation.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | """Hello, world!"""; x = \ | ||
| I002 | ||
2 | 1; y = 2 | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 |-"""Hello, world!"""; x = \ | ||
1 |+"""Hello, world!"""; from __future__ import annotations as _annotations; x = \ | ||
2 2 | 1; y = 2 | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
...ts/ruff__rules__isort__tests__required_import_with_alias_docstring_with_semicolon.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,15 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
docstring_with_semicolon.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | """Hello, world!"""; x = 1 | ||
| I002 | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 |-"""Hello, world!"""; x = 1 | ||
1 |+"""Hello, world!"""; from __future__ import annotations as _annotations; x = 1 | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
...rules/isort/snapshots/ruff__rules__isort__tests__required_import_with_alias_empty.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/src/rules/isort/mod.rs | ||
--- | ||
|
17 changes: 17 additions & 0 deletions
17
...t/snapshots/ruff__rules__isort__tests__required_import_with_alias_existing_import.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,17 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
existing_import.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | from __future__ import generator_stop | ||
| I002 | ||
2 | import os | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 |+from __future__ import annotations as _annotations | ||
1 2 | from __future__ import generator_stop | ||
2 3 | import os | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
...apshots/ruff__rules__isort__tests__required_import_with_alias_multiline_docstring.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,20 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
multiline_docstring.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | """a | ||
| I002 | ||
2 | b""" | ||
3 | # b | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 1 | """a | ||
2 2 | b""" | ||
3 3 | # b | ||
4 |+from __future__ import annotations as _annotations | ||
4 5 | import os | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
...c/rules/isort/snapshots/ruff__rules__isort__tests__required_import_with_alias_off.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,20 @@ | ||
--- | ||
source: crates/ruff/src/rules/isort/mod.rs | ||
--- | ||
off.py:1:1: I002 [*] Missing required import: `from __future__ import annotations as _annotations` | ||
| | ||
1 | # isort: off | ||
| I002 | ||
2 | | ||
3 | x = 1 | ||
| | ||
= help: Insert required import: `from future import annotations as _annotations` | ||
|
||
ℹ Fix | ||
1 1 | # isort: off | ||
2 |+from __future__ import annotations as _annotations | ||
2 3 | | ||
3 4 | x = 1 | ||
4 5 | # isort: on | ||
|
||
|
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