-
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.
Add autofix to move runtime-imports out of type-checking blocks (#4743)
- Loading branch information
1 parent
1a53996
commit 1156c65
Showing
11 changed files
with
317 additions
and
18 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
12 changes: 11 additions & 1 deletion
12
...ules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_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 |
---|---|---|
@@ -1,12 +1,22 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_1.py:4:26: TCH004 Move import `datetime.datetime` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_1.py:4:26: TCH004 [*] Move import `datetime.datetime` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from datetime import datetime | ||
| ^^^^^^^^ TCH004 | ||
6 | x = datetime | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from datetime import datetime | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from datetime import datetime | ||
5 |+ pass | ||
5 6 | x = datetime | ||
|
||
|
13 changes: 12 additions & 1 deletion
13
...les__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_11.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,13 +1,24 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_11.py:4:24: TCH004 Move import `typing.List` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_11.py:4:24: TCH004 [*] Move import `typing.List` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import List | ||
| ^^^^ TCH004 | ||
6 | | ||
7 | __all__ = ("List",) | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from typing import List | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import List | ||
5 |+ pass | ||
5 6 | | ||
6 7 | __all__ = ("List",) | ||
|
||
|
15 changes: 14 additions & 1 deletion
15
...les__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_12.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,13 +1,26 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_12.py:6:33: TCH004 Move import `collections.abc.Callable` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_12.py:6:33: TCH004 [*] Move import `collections.abc.Callable` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
6 | if TYPE_CHECKING: | ||
7 | from collections.abc import Callable | ||
| ^^^^^^^^ TCH004 | ||
8 | | ||
9 | AnyCallable: TypeAlias = Callable[..., Any] | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from __future__ import annotations | ||
2 2 | | ||
3 3 | from typing import Any, TYPE_CHECKING, TypeAlias | ||
4 |+from collections.abc import Callable | ||
4 5 | | ||
5 6 | if TYPE_CHECKING: | ||
6 |- from collections.abc import Callable | ||
7 |+ pass | ||
7 8 | | ||
8 9 | AnyCallable: TypeAlias = Callable[..., Any] | ||
|
||
|
14 changes: 13 additions & 1 deletion
14
...ules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_2.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,11 +1,23 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_2.py:4:26: TCH004 Move import `datetime.date` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_2.py:4:26: TCH004 [*] Move import `datetime.date` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from datetime import date | ||
| ^^^^ TCH004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from datetime import date | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from datetime import date | ||
5 |+ pass | ||
5 6 | | ||
6 7 | | ||
7 8 | def example(): | ||
|
||
|
14 changes: 13 additions & 1 deletion
14
...ules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_4.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,11 +1,23 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_4.py:4:24: TCH004 Move import `typing.Any` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_4.py:4:24: TCH004 [*] Move import `typing.Any` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import Any | ||
| ^^^ TCH004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING, Type | ||
2 |+from typing import Any | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import Any | ||
5 |+ pass | ||
5 6 | | ||
6 7 | | ||
7 8 | def example(*args: Any, **kwargs: Any): | ||
|
||
|
42 changes: 39 additions & 3 deletions
42
...ules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_5.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,25 +1,61 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_5.py:4:24: TCH004 Move import `typing.List` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_5.py:4:24: TCH004 [*] Move import `typing.List` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import List, Sequence, Set | ||
| ^^^^ TCH004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
TCH004_5.py:4:30: TCH004 Move import `typing.Sequence` out of type-checking block. Import is used for more than type hinting. | ||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from typing import List | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import List, Sequence, Set | ||
5 |+ from typing import Sequence, Set | ||
5 6 | | ||
6 7 | | ||
7 8 | def example(a: List[int], /, b: Sequence[int], *, c: Set[int]): | ||
|
||
TCH004_5.py:4:30: TCH004 [*] Move import `typing.Sequence` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import List, Sequence, Set | ||
| ^^^^^^^^ TCH004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from typing import Sequence | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import List, Sequence, Set | ||
5 |+ from typing import List, Set | ||
5 6 | | ||
6 7 | | ||
7 8 | def example(a: List[int], /, b: Sequence[int], *, c: Set[int]): | ||
|
||
TCH004_5.py:4:40: TCH004 Move import `typing.Set` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_5.py:4:40: TCH004 [*] Move import `typing.Set` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import List, Sequence, Set | ||
| ^^^ TCH004 | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from typing import Set | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import List, Sequence, Set | ||
5 |+ from typing import List, Sequence | ||
5 6 | | ||
6 7 | | ||
7 8 | def example(a: List[int], /, b: Sequence[int], *, c: Set[int]): | ||
|
||
|
28 changes: 26 additions & 2 deletions
28
...ules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_9.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,22 +1,46 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
TCH004_9.py:4:24: TCH004 Move import `typing.Tuple` out of type-checking block. Import is used for more than type hinting. | ||
TCH004_9.py:4:24: TCH004 [*] Move import `typing.Tuple` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import Tuple, List, Dict | ||
| ^^^^^ TCH004 | ||
6 | | ||
7 | x: Tuple | ||
| | ||
= help: Move out of type-checking block | ||
|
||
TCH004_9.py:4:31: TCH004 Move import `typing.List` out of type-checking block. Import is used for more than type hinting. | ||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from typing import Tuple | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import Tuple, List, Dict | ||
5 |+ from typing import List, Dict | ||
5 6 | | ||
6 7 | x: Tuple | ||
7 8 | | ||
|
||
TCH004_9.py:4:31: TCH004 [*] Move import `typing.List` out of type-checking block. Import is used for more than type hinting. | ||
| | ||
4 | if TYPE_CHECKING: | ||
5 | from typing import Tuple, List, Dict | ||
| ^^^^ TCH004 | ||
6 | | ||
7 | x: Tuple | ||
| | ||
= help: Move out of type-checking block | ||
|
||
ℹ Suggested fix | ||
1 1 | from typing import TYPE_CHECKING | ||
2 |+from typing import List | ||
2 3 | | ||
3 4 | if TYPE_CHECKING: | ||
4 |- from typing import Tuple, List, Dict | ||
5 |+ from typing import Tuple, Dict | ||
5 6 | | ||
6 7 | x: Tuple | ||
7 8 | | ||
|
||
|
Oops, something went wrong.