From 5070e53b906e642843e864ff4a25ec6206b2f580 Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Thu, 8 Feb 2024 22:42:37 +0900 Subject: [PATCH 1/3] Allow multi-line strings in `seval` --- src/JlWrap/module.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JlWrap/module.jl b/src/JlWrap/module.jl index e88a6a4e..8d879ae5 100644 --- a/src/JlWrap/module.jl +++ b/src/JlWrap/module.jl @@ -10,7 +10,7 @@ function pyjlmodule_dir(self::Module) end function pyjlmodule_seval(self::Module, expr::Py) - Py(Base.eval(self, Meta.parse(strip(pyconvert(String, expr))))) + Py(Base.eval(self, Meta.parseall(strip(pyconvert(String, expr))))) end function init_module() From 21a65dc9ce9b2f7877b0f2ed12e5d7e1541def98 Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Thu, 8 Feb 2024 13:53:12 +0000 Subject: [PATCH 2/3] Add test for issue 433 --- pytest/test_all.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pytest/test_all.py b/pytest/test_all.py index af7111e6..0364db6b 100644 --- a/pytest/test_all.py +++ b/pytest/test_all.py @@ -17,3 +17,22 @@ def test_issue_394(): assert jl.f is f assert jl.y is y assert jl.seval("f(x)") == 4 + +def test_issue_433(): + "https://github.com/JuliaPy/PythonCall.jl/issues/433" + from juliacall import Main as jl + + # Smoke test + jl.seval("x=1\nx=1") + assert jl.x == 1 + + # Do multiple things + out = jl.seval( + """ + function _issue_433_g(x) + return x^2 + end + _issue_433_g(5) + """ + ) + assert out == 25 \ No newline at end of file From cd7450fe74555a3c3e4f8cd7800ea77e4652b4b5 Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Thu, 8 Feb 2024 13:53:29 +0000 Subject: [PATCH 3/3] Fix newline --- pytest/test_all.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest/test_all.py b/pytest/test_all.py index 0364db6b..d34cd1b9 100644 --- a/pytest/test_all.py +++ b/pytest/test_all.py @@ -35,4 +35,4 @@ def test_issue_433(): _issue_433_g(5) """ ) - assert out == 25 \ No newline at end of file + assert out == 25