Skip to content

Commit 16c2374

Browse files
LilithHafnerLilith Hafner
and
Lilith Hafner
authored
Strip whitespace before parsing in seval (#380)
* 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]>
1 parent 5f56a9b commit 16c2374

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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(pyconvert(String, expr))))
13+
Py(Base.eval(self, Meta.parse(strip(pyconvert(String, expr)))))
1414
end
1515

1616
function init_jlwrap_module()

test/jlwrap.jl

+9-4
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ end
149149
end
150150

151151
@testitem "base" begin
152-
152+
153153
end
154154

155155
@testitem "callback" begin
156-
156+
157157
end
158158

159159
@testitem "dict" begin
@@ -193,6 +193,11 @@ end
193193
@testset "bool" begin
194194
@test pytruth(pyjl(PythonCall))
195195
end
196+
@testset "seval" begin
197+
m = Py(Main)
198+
@test pyconvert(Any, m.seval("1 + 1")) === 2 # Basic behavior
199+
@test pyconvert(Any, m.seval("1 + 1\n ")) === 2 # Trailing whitespace
200+
end
196201
end
197202

198203
@testitem "number" begin
@@ -218,11 +223,11 @@ end
218223
end
219224

220225
@testitem "objectarray" begin
221-
226+
222227
end
223228

224229
@testitem "raw" begin
225-
230+
226231
end
227232

228233
@testitem "set" begin

0 commit comments

Comments
 (0)