Skip to content

Commit 5d1efca

Browse files
karlduderstadtctrueden
authored andcommitted
SciJava Python scripting: no final eval of assignments
This change ensures the last line of scripts are only evaulated for a return value if they do not contain an assignment.
1 parent 84230c9 commit 5d1efca

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/scyjava/_script.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def apply(self, arg):
7575

7676
block = ast.parse(str(arg.script), mode="exec")
7777
last = None
78-
if len(block.body) > 0 and hasattr(block.body[-1], "value"):
78+
if (
79+
len(block.body) > 0
80+
and hasattr(block.body[-1], "value")
81+
and not isinstance(block.body[-1], ast.Assign)
82+
):
7983
# Last statement of the script looks like an expression. Evaluate!
8084
last = ast.Expression(block.body.pop().value)
8185

0 commit comments

Comments
 (0)