Skip to content

Commit

Permalink
Fix traceback raised on an expression list assignment
Browse files Browse the repository at this point in the history
When there is an assignment using a pattern_list and expression_list,
the current code will iterate through each assignment. However, the
current code assumes it can use context['node'], which is not the
expected node during the parse.

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb committed Apr 23, 2024
1 parent 30b7bbd commit 4105c24
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion precli/parsers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def visit_assignment(self, nodes: list[Node]):
nodes[2].children[1]
)

if self.context["node"].children:
if nodes[2].children:
# (attribute | identifier) argument_list
func_node = nodes[2].children[0]
var_node = self._get_var_node(func_node)
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/parsers/examples/expression_list_assignment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import torch
import ssl


torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
x = torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
b, *_, device = *x.shape, x.device
ssl_ctx1, ssl_ctx2 = ssl.SSLContext(), ssl.SSLContext()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import torch


torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
x = torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
b, *_, device = *x.shape, x.device
9 changes: 9 additions & 0 deletions tests/unit/parsers/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def test_expression_list_assignment(self):
results = self.parser.parse(artifact)
self.assertEqual(0, len(results))

def test_expression_list_assignment_uneven(self):
artifact = Artifact(
os.path.join(
self.base_path, "expression_list_assignment_uneven.py"
)
)
results = self.parser.parse(artifact)
self.assertEqual(0, len(results))

def test_importlib_import_module(self):
artifact = Artifact(
os.path.join(self.base_path, "importlib_import_module.py")
Expand Down

0 comments on commit 4105c24

Please sign in to comment.