Skip to content

Commit

Permalink
Fixed issue with tuples in assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
AryazE committed Aug 21, 2024
1 parent c3cb741 commit 1e3ab5a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/dynapyt/instrument/CodeInstrumenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,12 @@ def leave_Assign(self, original_node, updated_node):
val_arg = cst.Arg(value=updated_node.value.value.item)
elif m.matches(updated_node.value, m.Yield()):
val_arg = cst.Arg(value=updated_node.value.value)
elif m.matches(updated_node.value, m.Tuple()):
val_arg = cst.Arg(
value=updated_node.value.with_changes(
lpar=[cst.LeftParen()], rpar=[cst.RightParen()]
)
)
else:
val_arg = cst.Arg(value=updated_node.value)
left_arg = cst.Arg(
Expand Down Expand Up @@ -1149,6 +1155,12 @@ def leave_AnnAssign(self, original_node, updated_node):
iid_arg = cst.Arg(value=cst.Integer(value=str(iid)))
if m.matches(updated_node.value, m.Yield()):
val_arg = cst.Arg(value=updated_node.value.value)
elif m.matches(updated_node.value, m.Tuple()):
val_arg = cst.Arg(
value=updated_node.value.with_changes(
lpar=[cst.LeftParen()], rpar=[cst.RightParen()]
)
)
else:
val_arg = cst.Arg(value=updated_node.value)
left_arg = cst.Arg(
Expand Down
2 changes: 2 additions & 0 deletions tests/trace_single_hook/write/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ Writing test to [('b',)]
Writing testtesttesttesttesttesttesttesttesttest to [('c',)]
Writing testing to [('b',)]
Writing 30 to [('a',)]
Writing ('test',) to [('d',)]
Writing ('test',) to [('e',)]
end execution
2 changes: 2 additions & 0 deletions tests/trace_single_hook/write/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
c = a * b
b += "ing"
a *= 3
d = "test",
e: str = "test",

0 comments on commit 1e3ab5a

Please sign in to comment.