File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -176,7 +176,10 @@ def visit_Assign(self, node: ast.Assign) -> None:
176176
177177 self .generic_visit (node )
178178
179- # TODO: AnnAssign
179+ def visit_AnnAssign (self , node : ast .AnnAssign ) -> None :
180+ if isinstance (node .target , ast .Name ):
181+ self .define (node .target .id , node )
182+ self .generic_visit (node )
180183
181184 def visit_Name (self , node : ast .Name ) -> None :
182185 if isinstance (node .ctx , ast .Load ):
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ def git_dir(tmpdir):
8383 (
8484 # assign
8585 'x = 1\n print(x)\n ' ,
86+ pytest .param ('x: int = 1\n print(x)\n ' , id = 'annotated assignment' ),
8687 # function
8788 'def f(): ...\n '
8889 'print(f())\n ' ,
@@ -313,3 +314,16 @@ def test_unused_posonly_argument(git_dir, capsys):
313314 assert dead .main (())
314315 out , _ = capsys .readouterr ()
315316 assert out == 'unused is never read, defined in f.py:1\n '
317+
318+
319+ def test_unused_annotated_assignment (git_dir , capsys ):
320+ git_dir .join ('f.py' ).write (
321+ 'from typing import Final\n '
322+ 'SOME_CONSTANT: Final = 123\n '
323+ 'x = {}\n '
324+ 'x[1]: int\n ' ,
325+ )
326+ subprocess .check_call (('git' , 'add' , '.' ))
327+ assert dead .main (())
328+ out , _ = capsys .readouterr ()
329+ assert out == 'SOME_CONSTANT is never read, defined in f.py:2\n '
You can’t perform that action at this time.
0 commit comments