mirror of https://github.com/pyodide/pyodide.git
fix iodide-project/iodide#1423: Don't crash if there is no Python code
This commit is contained in:
parent
829285339a
commit
9f7f4826ce
|
@ -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):
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue