File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments