-
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.
Mark quotes as unnecessary for non-evaluated annotations (#11485)
## Summary Similar to #11414, this PR extends `UP037` to flag quoted annotations that are located in positions that won't be evaluated at runtime. For example, the quotes on `Tuple` are unnecessary in: ```python from typing import TYPE_CHECKING if TYPE_CHECKING: from typing import Tuple def foo(): x: "Tuple[int, int]" = (0, 0) foo() ```
- Loading branch information
1 parent
573facd
commit 519a650
Showing
8 changed files
with
88 additions
and
34 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
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
crates/ruff_linter/resources/test/fixtures/pyupgrade/UP037_1.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 typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Tuple | ||
|
||
|
||
def foo(): | ||
# UP037 | ||
x: "Tuple[int, int]" = (0, 0) | ||
print(x) | ||
|
||
|
||
# OK | ||
X: "Tuple[int, int]" = (0, 0) |
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
22 changes: 22 additions & 0 deletions
22
...inter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP037_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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs | ||
--- | ||
UP037_1.py:9:8: UP037 [*] Remove quotes from type annotation | ||
| | ||
7 | def foo(): | ||
8 | # UP037 | ||
9 | x: "Tuple[int, int]" = (0, 0) | ||
| ^^^^^^^^^^^^^^^^^ UP037 | ||
10 | print(x) | ||
| | ||
= help: Remove quotes | ||
|
||
ℹ Safe fix | ||
6 6 | | ||
7 7 | def foo(): | ||
8 8 | # UP037 | ||
9 |- x: "Tuple[int, int]" = (0, 0) | ||
9 |+ x: Tuple[int, int] = (0, 0) | ||
10 10 | print(x) | ||
11 11 | | ||
12 12 | |