Skip to content

Commit

Permalink
Strip whitespace before parsing in seval (#380)
Browse files Browse the repository at this point in the history
* strip whitespace before parsing in seval

* add seval tests

* move tests to python

* move back to Julia side :(

---------

Co-authored-by: Lilith Hafner <[email protected]>
  • Loading branch information
LilithHafner and Lilith Hafner authored Oct 11, 2023
1 parent 5f56a9b commit 16c2374
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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(pyconvert(String, expr))))
Py(Base.eval(self, Meta.parse(strip(pyconvert(String, expr)))))
end

function init_jlwrap_module()
Expand Down
13 changes: 9 additions & 4 deletions test/jlwrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ end
end

@testitem "base" begin

end

@testitem "callback" begin

end

@testitem "dict" begin
Expand Down Expand Up @@ -193,6 +193,11 @@ end
@testset "bool" begin
@test pytruth(pyjl(PythonCall))
end
@testset "seval" begin
m = Py(Main)
@test pyconvert(Any, m.seval("1 + 1")) === 2 # Basic behavior
@test pyconvert(Any, m.seval("1 + 1\n ")) === 2 # Trailing whitespace
end
end

@testitem "number" begin
Expand All @@ -218,11 +223,11 @@ end
end

@testitem "objectarray" begin

end

@testitem "raw" begin

end

@testitem "set" begin
Expand Down

0 comments on commit 16c2374

Please sign in to comment.