Skip to content

Commit

Permalink
Allow multi-block expressions in seval (#452)
Browse files Browse the repository at this point in the history
* Allow multi-line strings in `seval`

* Add test for issue 433

* Fix newline
  • Loading branch information
MilesCranmer authored Feb 13, 2024
1 parent 8403d74 commit b84c3cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions pytest/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/JlWrap/module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b84c3cb

Please sign in to comment.