Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Test: ensure that we treat strings in `typing.Annotation` as type definitions."""

from pathlib import Path
from re import RegexFlag
from typing import Annotated

p: Annotated["Path", int] = 1
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ impl<'a> Visitor<'a> for Checker<'a> {
{
let mut iter = elts.iter();
if let Some(expr) = iter.next() {
self.visit_expr(expr);
self.visit_type_definition(expr);
}
for expr in iter {
self.visit_non_type_definition(expr);
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/pyflakes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mod tests {
#[test_case(Rule::UnusedImport, Path::new("F401_20.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_21.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_22.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_23.py"))]
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.py"))]
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.ipynb"))]
#[test_case(Rule::UndefinedLocalWithImportStar, Path::new("F403.py"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
---
F401_23.py:4:16: F401 [*] `re.RegexFlag` imported but unused
|
3 | from pathlib import Path
4 | from re import RegexFlag
| ^^^^^^^^^ F401
5 | from typing import Annotated
|
= help: Remove unused import: `re.RegexFlag`

ℹ Safe fix
1 1 | """Test: ensure that we treat strings in `typing.Annotation` as type definitions."""
2 2 |
3 3 | from pathlib import Path
4 |-from re import RegexFlag
5 4 | from typing import Annotated
6 5 |
7 6 | p: Annotated["Path", int] = 1