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

This commit is contained in:
Michael Droettboom 2019-01-23 16:59:52 -05:00
parent 829285339a
commit 9f7f4826ce
2 changed files with 8 additions and 0 deletions

View File

@ -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]

View File

@ -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