|
298 | 298 | function _getproperty(o::PyObject, s::Union{AbstractString,Symbol})
|
299 | 299 | ispynull(o) && throw(ArgumentError("ref of NULL PyObject"))
|
300 | 300 | p = ccall((@pysym :PyObject_GetAttrString), PyPtr, (PyPtr, Cstring), o, s)
|
301 |
| - p == C_NULL && pyerr_clear() |
| 301 | + if p == C_NULL && pyerr_occurred() |
| 302 | + e = pyerror("PyObject_GetAttrString") |
| 303 | + if PyPtr(e.T) != @pyglobalobjptr(:PyExc_AttributeError) |
| 304 | + throw(e) |
| 305 | + end |
| 306 | + pyerr_clear() |
| 307 | + end |
302 | 308 | return p
|
303 | 309 | end
|
304 | 310 |
|
@@ -327,15 +333,17 @@ setproperty!(o::PyObject, s::Symbol, v) = _setproperty!(o,s,v)
|
327 | 333 | setproperty!(o::PyObject, s::AbstractString, v) = _setproperty!(o,s,v)
|
328 | 334 |
|
329 | 335 | function _setproperty!(o::PyObject, s::Union{Symbol,AbstractString}, v)
|
330 |
| - if ispynull(o) |
331 |
| - throw(ArgumentError("assign of NULL PyObject")) |
332 |
| - end |
333 |
| - if -1 == ccall((@pysym :PyObject_SetAttrString), Cint, |
334 |
| - (PyPtr, Cstring, PyPtr), o, s, PyObject(v)) |
| 336 | + ispynull(o) && throw(ArgumentError("assign of NULL PyObject")) |
| 337 | + p = ccall((@pysym :PyObject_SetAttrString), Cint, (PyPtr, Cstring, PyPtr), o, s, PyObject(v)) |
| 338 | + if p == -1 && pyerr_occurred() |
| 339 | + e = pyerror("PyObject_SetAttrString") |
| 340 | + if PyPtr(e.T) != @pyglobalobjptr(:PyExc_AttributeError) |
| 341 | + throw(e) |
| 342 | + end |
335 | 343 | pyerr_clear()
|
336 | 344 | throw(KeyError(s))
|
337 | 345 | end
|
338 |
| - o |
| 346 | + return o |
339 | 347 | end
|
340 | 348 |
|
341 | 349 | function getindex(o::PyObject, s::T) where T<:Union{Symbol, AbstractString}
|
|
0 commit comments