Skip to content

Commit

Permalink
Fix annotated assign statement
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch committed Nov 27, 2023
1 parent a3ba236 commit a9238ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions guppy/cfg/bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def visit_AugAssign(self, node: ast.AugAssign) -> None:
for name in name_nodes_in_ast(node.target):
self.stats.assigned[name.id] = node

def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
self.stats.update_used(node.value)
for name in name_nodes_in_ast(node.target):
self.stats.assigned[name.id] = node

def visit_NestedFunctionDef(self, node: NestedFunctionDef) -> None:
# In order to compute the used external variables in a nested function
# definition, we have to run live variable analysis first
Expand Down
5 changes: 5 additions & 0 deletions guppy/cfg/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def visit_AugAssign(
) -> Optional[BB]:
return self._build_node_value(node, bb)

def visit_AnnAssign(
self, node: ast.AnnAssign, bb: BB, jumps: Jumps
) -> Optional[BB]:
return self._build_node_value(node, bb)

def visit_Expr(self, node: ast.Expr, bb: BB, jumps: Jumps) -> Optional[BB]:
# This is an expression statement where the value is discarded
node.value, bb = ExprBuilder.build(node.value, self.cfg, bb)
Expand Down

0 comments on commit a9238ec

Please sign in to comment.