Skip to content

Commit b84c3cb

Browse files
authored
Allow multi-block expressions in seval (#452)
* Allow multi-line strings in `seval` * Add test for issue 433 * Fix newline
1 parent 8403d74 commit b84c3cb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pytest/test_all.py

+19
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,22 @@ def test_issue_394():
1717
assert jl.f is f
1818
assert jl.y is y
1919
assert jl.seval("f(x)") == 4
20+
21+
def test_issue_433():
22+
"https://github.com/JuliaPy/PythonCall.jl/issues/433"
23+
from juliacall import Main as jl
24+
25+
# Smoke test
26+
jl.seval("x=1\nx=1")
27+
assert jl.x == 1
28+
29+
# Do multiple things
30+
out = jl.seval(
31+
"""
32+
function _issue_433_g(x)
33+
return x^2
34+
end
35+
_issue_433_g(5)
36+
"""
37+
)
38+
assert out == 25

src/JlWrap/module.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function pyjlmodule_dir(self::Module)
1010
end
1111

1212
function pyjlmodule_seval(self::Module, expr::Py)
13-
Py(Base.eval(self, Meta.parse(strip(pyconvert(String, expr)))))
13+
Py(Base.eval(self, Meta.parseall(strip(pyconvert(String, expr)))))
1414
end
1515

1616
function init_module()

0 commit comments

Comments
 (0)