Skip to content

Commit d2b7859

Browse files
committed
Improve detection for skipping deepcopy
1 parent d95fb22 commit d2b7859

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎pythonwhat/tasks.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ def taskRunEval(
368368
mode = "exec"
369369
else:
370370
mode = "eval"
371-
tree = ast.Expression(tree)
371+
if not isinstance(tree, (ast.Module, ast.Expression, ast.Expr)):
372+
tree = ast.Expression(tree)
372373

373374
# Expression code takes precedence over tree code
374375
if expr_code:
@@ -379,8 +380,12 @@ def taskRunEval(
379380

380381
# Set up environment --------------------------------------------------
381382
# avoid deepy copy if specified, or just looking up variable by name
383+
if isinstance(tree, ast.Module):
384+
tree = tree.body
382385
if isinstance(tree, ast.Expression):
383386
tree = tree.body
387+
if isinstance(tree, ast.Expr):
388+
tree = tree.value
384389
if not copy or (
385390
isinstance(tree, (ast.Name, ast.Subscript))
386391
and isinstance(tree.ctx, ast.Load)

0 commit comments

Comments
 (0)