Skip to content

Commit b5ec894

Browse files
committed
bugfix in _getproperty
1 parent 62ebd0a commit b5ec894

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/PyCall.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,15 @@ end
296296
# conversion.
297297

298298
function _getproperty(o::PyObject, s::Union{AbstractString,Symbol})
299-
if ispynull(o)
300-
throw(ArgumentError("ref of NULL PyObject"))
301-
end
302-
return ccall((@pysym :PyObject_GetAttrString), PyPtr, (PyPtr, Cstring), o, s)
299+
ispynull(o) && throw(ArgumentError("ref of NULL PyObject"))
300+
p = ccall((@pysym :PyObject_GetAttrString), PyPtr, (PyPtr, Cstring), o, s)
301+
p == C_NULL && pyerr_clear()
302+
return p
303303
end
304304

305305
function __getproperty(o::PyObject, s::Union{AbstractString,Symbol})
306306
p = _getproperty(o, s)
307-
if p == C_NULL
308-
pyerr_clear()
309-
throw(KeyError(s))
310-
end
307+
p == C_NULL && throw(KeyError(s))
311308
return PyObject(p)
312309
end
313310

@@ -862,7 +859,7 @@ if pyversion >= v"3.3"
862859
else
863860
function empty!(o::PyObject)
864861
p = _getproperty(o, "clear")
865-
if p != PyNULL() # for dict, set, etc.
862+
if p != NULL # for dict, set, etc.
866863
pydecref(pycall(PyObject(o)."clear", PyObject))
867864
else
868865
for i = length(o)-1:-1:0

0 commit comments

Comments
 (0)