-
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.
Recognize all symbols named
TYPE_CHECKING
for `in_type_checking_blo…
…ck` (#15719) Closes #15681 ## Summary This changes `analyze::typing::is_type_checking_block` to recognize all symbols named "TYPE_CHECKING". This matches the current behavior of mypy and pyright as well as `flake8-type-checking`. It also drops support for detecting `if False:` and `if 0:` as type checking blocks. This used to be an option for providing backwards compatibility with Python versions that did not have a `typing` module, but has since been removed from the typing spec and is no longer supported by any of the mainstream type checkers. ## Test Plan `cargo nextest run` --------- Co-authored-by: Micha Reiser <micha@reiser.io>
- Loading branch information
1 parent
81059d0
commit 8fcac0f
Showing
8 changed files
with
192 additions
and
15 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
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
26 changes: 26 additions & 0 deletions
26
...apshots/ruff_linter__rules__flake8_type_checking__tests__github_issue_15681_fix_test.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,26 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs | ||
--- | ||
<filename>:4:8: TC003 [*] Move standard library import `pathlib` into a type-checking block | ||
| | ||
2 | from __future__ import annotations | ||
3 | | ||
4 | import pathlib # TC003 | ||
| ^^^^^^^ TC003 | ||
5 | | ||
6 | TYPE_CHECKING = False | ||
| | ||
= help: Move into type-checking block | ||
|
||
ℹ Unsafe fix | ||
1 1 | | ||
2 2 | from __future__ import annotations | ||
3 3 | | ||
4 |-import pathlib # TC003 | ||
5 4 | | ||
6 5 | TYPE_CHECKING = False | ||
7 6 | if TYPE_CHECKING: | ||
7 |+ import pathlib | ||
8 8 | from types import TracebackType | ||
9 9 | | ||
10 10 | def foo(tb: TracebackType) -> pathlib.Path: ... |
4 changes: 4 additions & 0 deletions
4
.../ruff_linter__rules__flake8_type_checking__tests__github_issue_15681_regression_test.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