File tree 4 files changed +29
-1
lines changed
resources/test/fixtures/pyflakes
4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
1
+ """Test: ensure that we treat strings in `typing.Annotation` as type definitions."""
2
+
3
+ from pathlib import Path
4
+ from re import RegexFlag
5
+ from typing import Annotated
6
+
7
+ p : Annotated ["Path" , int ] = 1
Original file line number Diff line number Diff line change @@ -1348,7 +1348,7 @@ impl<'a> Visitor<'a> for Checker<'a> {
1348
1348
{
1349
1349
let mut iter = elts. iter ( ) ;
1350
1350
if let Some ( expr) = iter. next ( ) {
1351
- self . visit_expr ( expr) ;
1351
+ self . visit_type_definition ( expr) ;
1352
1352
}
1353
1353
for expr in iter {
1354
1354
self . visit_non_type_definition ( expr) ;
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ mod tests {
55
55
#[ test_case( Rule :: UnusedImport , Path :: new( "F401_20.py" ) ) ]
56
56
#[ test_case( Rule :: UnusedImport , Path :: new( "F401_21.py" ) ) ]
57
57
#[ test_case( Rule :: UnusedImport , Path :: new( "F401_22.py" ) ) ]
58
+ #[ test_case( Rule :: UnusedImport , Path :: new( "F401_23.py" ) ) ]
58
59
#[ test_case( Rule :: ImportShadowedByLoopVar , Path :: new( "F402.py" ) ) ]
59
60
#[ test_case( Rule :: ImportShadowedByLoopVar , Path :: new( "F402.ipynb" ) ) ]
60
61
#[ test_case( Rule :: UndefinedLocalWithImportStar , Path :: new( "F403.py" ) ) ]
Original file line number Diff line number Diff line change
1
+ -- -
2
+ source : crates / ruff_linter / src / rules / pyflakes / mod .rs
3
+ -- -
4
+ F401_23 .py :4 :16 : F401 [* ] ` re.RegexFlag` imported but unused
5
+ |
6
+ 3 | from pathlib import Path
7
+ 4 | from re import RegexFlag
8
+ | ^^^^^^^^^ F401
9
+ 5 | from typing import Annotated
10
+ |
11
+ = help : Remove unused import : ` re.RegexFlag`
12
+
13
+ ℹ Safe fix
14
+ 1 1 | " " " Test: ensure that we treat strings in `typing.Annotation` as type definitions." " "
15
+ 2 2 |
16
+ 3 3 | from pathlib import Path
17
+ 4 | - from re import RegexFlag
18
+ 5 4 | from typing import Annotated
19
+ 6 5 |
20
+ 7 6 | p : Annotated [" Path" , int ] = 1
You can’t perform that action at this time.
0 commit comments