Skip to content

Commit

Permalink
Avoid removing quotes from runtime annotations (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 6, 2023
1 parent 60ee1d2 commit 3bca987
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 83 deletions.
12 changes: 6 additions & 6 deletions crates/ruff/resources/test/fixtures/pyupgrade/UP037.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ class D(TypedDict):

x: NamedTuple(typename="X", fields=[("foo", "int")])

x = TypeVar("x", "str", "int")

x = cast("str", x)

X = List["MyClass"]

X: MyCallable("X")


Expand Down Expand Up @@ -106,3 +100,9 @@ def foo(*, inplace):


x: Annotated[1:2] = ...

x = TypeVar("x", "str", "int")

x = cast("str", x)

X = List["MyClass"]
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4391,7 +4391,7 @@ impl<'a> Checker<'a> {
self.deferred_string_type_definitions.pop()
{
if let Ok(mut expr) = parser::parse_expression(expression, "<filename>") {
if self.annotations_future_enabled {
if in_annotation && self.annotations_future_enabled {
if self.settings.rules.enabled(&Rule::QuotedAnnotation) {
pyupgrade::rules::quoted_annotation(self, expression, range);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/rules/pyupgrade/mod.rs
source: crates/ruff/src/rules/pyupgrade/mod.rs
expression: diagnostics
---
- kind:
Expand Down Expand Up @@ -510,90 +510,18 @@ expression: diagnostics
QuotedAnnotation: ~
location:
row: 69
column: 17
end_location:
row: 69
column: 22
fix:
content:
- str
location:
row: 69
column: 17
end_location:
row: 69
column: 22
parent: ~
- kind:
QuotedAnnotation: ~
location:
row: 69
column: 24
end_location:
row: 69
column: 29
fix:
content:
- int
location:
row: 69
column: 24
end_location:
row: 69
column: 29
parent: ~
- kind:
QuotedAnnotation: ~
location:
row: 71
column: 9
end_location:
row: 71
column: 14
fix:
content:
- str
location:
row: 71
column: 9
end_location:
row: 71
column: 14
parent: ~
- kind:
QuotedAnnotation: ~
location:
row: 73
column: 9
end_location:
row: 73
column: 18
fix:
content:
- MyClass
location:
row: 73
column: 9
end_location:
row: 73
column: 18
parent: ~
- kind:
QuotedAnnotation: ~
location:
row: 75
column: 14
end_location:
row: 75
row: 69
column: 17
fix:
content:
- X
location:
row: 75
row: 69
column: 14
end_location:
row: 75
row: 69
column: 17
parent: ~

0 comments on commit 3bca987

Please sign in to comment.