Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix traceback raised on an expression list assignment #439

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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