File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -2542,11 +2542,12 @@ def _is_never_evaluated(
25422542
25432543 @staticmethod
25442544 def _is_variable_annotation_in_function (node : nodes .Name ) -> bool :
2545+ ann_assign = utils .get_node_first_ancestor_of_type (node , nodes .AnnAssign )
25452546 return (
2546- isinstance ( node . parent , nodes . AnnAssign )
2547- and node is node . parent .annotation
2547+ ann_assign
2548+ and ( node is ann_assign . annotation or ann_assign .annotation . parent_of ( node ))
25482549 and utils .get_node_first_ancestor_of_type ( # type: ignore[return-value]
2549- node . parent , nodes .FunctionDef
2550+ ann_assign , nodes .FunctionDef
25502551 )
25512552 )
25522553
Original file line number Diff line number Diff line change @@ -16,3 +16,10 @@ def func():
1616 first = datetime .now () # [used-before-assignment]
1717 second = datetime .now ()
1818 return first , second
19+
20+
21+ def annotated_declaration_with_type_subscript ():
22+ dt_list : list [datetime ]
23+ dt_list = [datetime .now (), datetime .now ()] # [used-before-assignment]
24+
25+ return dt_list
Original file line number Diff line number Diff line change 11used-before-assignment:10:13:10:21:func_two:Using variable 'datetime' before assignment:INFERENCE
22used-before-assignment:16:12:16:20:func:Using variable 'datetime' before assignment:INFERENCE
3+ used-before-assignment:23:15:23:23:annotated_declaration_with_type_subscript:Using variable 'datetime' before assignment:INFERENCE
You can’t perform that action at this time.
0 commit comments