Commit 02f3b134 authored by Michael Droettboom's avatar Michael Droettboom Committed by GitHub

Merge pull request #303 from mdboom/eval-nothing

fix iodide-project/iodide#1423: Don't crash if there is no Python code
parents 1049ba78 9f7f4826
......@@ -29,6 +29,9 @@ def eval_code(code, ns):
code = dedent(code)
mod = ast.parse(code)
if len(mod.body) == 0:
return None
if isinstance(mod.body[-1], ast.Expr):
expr = ast.Expression(mod.body[-1].value)
del mod.body[-1]
......
......@@ -645,3 +645,8 @@ def test_py(selenium_standalone):
)
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