Skip to content

Commit 6ea3223

Browse files
author
Christopher Doris
committed
fix error supression bug in pywith
1 parent a309163 commit 6ea3223

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Diff for: docs/src/releasenotes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release Notes
22

3-
## 0.9.7
3+
## 0.9.7 (Unreleased)
44
* If CondaPkg is using the Null backend, PythonCall will now use `python` from the PATH.
55
* Bug fixes.
66

Diff for: src/compat/with.jl

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@ function pywith(f, o, d = nothing)
1414
value = t.__enter__(o)
1515
exited = false
1616
try
17-
f(value)
17+
return f(value)
1818
catch exc
1919
if exc isa PyException
2020
exited = true
2121
if pytruth(exit(o, exc.t, exc.v, exc.b))
22-
rethrow()
23-
else
24-
d
22+
return d
2523
end
26-
else
27-
rethrow()
2824
end
25+
rethrow()
2926
finally
3027
exited || exit(o, pybuiltins.None, pybuiltins.None, pybuiltins.None)
3128
end

Diff for: test/compat.jl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@testitem "pywith" begin
2+
@testset "no error" begin
3+
tdir = pyimport("tempfile").TemporaryDirectory()
4+
tname = pyconvert(String, tdir.name)
5+
@test isdir(tname)
6+
pywith(tdir) do name
7+
@test pyconvert(String, name) == tname
8+
end
9+
@test !isdir(tname)
10+
end
11+
@testset "error" begin
12+
tdir = pyimport("tempfile").TemporaryDirectory()
13+
tname = pyconvert(String, tdir.name)
14+
@test isdir(tname)
15+
@test_throws PyException pywith(name -> name.invalid_attr, tdir)
16+
@test !isdir(tname)
17+
end
18+
end

0 commit comments

Comments
 (0)