Commit 9f7f4826 authored by Michael Droettboom's avatar Michael Droettboom

fix iodide-project/iodide#1423: Don't crash if there is no Python code

parent 82928533
...@@ -29,6 +29,9 @@ def eval_code(code, ns): ...@@ -29,6 +29,9 @@ def eval_code(code, ns):
code = dedent(code) code = dedent(code)
mod = ast.parse(code) mod = ast.parse(code)
if len(mod.body) == 0:
return None
if isinstance(mod.body[-1], ast.Expr): if isinstance(mod.body[-1], ast.Expr):
expr = ast.Expression(mod.body[-1].value) expr = ast.Expression(mod.body[-1].value)
del mod.body[-1] del mod.body[-1]
......
...@@ -645,3 +645,8 @@ def test_py(selenium_standalone): ...@@ -645,3 +645,8 @@ def test_py(selenium_standalone):
) )
assert selenium_standalone.run_js('return pyodide.globals.func()') == 42 assert selenium_standalone.run_js('return pyodide.globals.func()') == 42
def test_eval_nothing(selenium):
assert selenium.run('# comment') is None
assert selenium.run('') is None
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment