Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/PyCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ function trygetproperty(o::PyObject, s::AbstractString, d)
return p == C_NULL ? d : PyObject(p)
end

propertynames(o::PyObject) = ispynull(o) ? Symbol[] : map(x->Symbol(first(x)), PyIterator{PyObject}(pycall(inspect."getmembers", PyObject, o)))
function propertynames(o::PyObject)
ispynull(o) && return Symbol[]
return convert(Vector{Symbol}, ccall((@pysym :PyObject_Dir), PyObject, (PyPtr,), o))
end

# avoiding method ambiguity
setproperty!(o::PyObject, s::Symbol, v) = _setproperty!(o,s,v)
Expand Down Expand Up @@ -366,8 +369,7 @@ hasproperty(o::PyObject, s::AbstractString) = pyhasproperty(o, s)

#########################################################################

keys(o::PyObject) = Symbol[m[1] for m in pycall(inspect."getmembers",
PyVector{Tuple{Symbol,PyObject}}, o)]
keys(o::PyObject) = convert(Vector{Symbol}, ccall((@pysym :PyObject_Dir), PyObject, (PyPtr,), o))

#########################################################################
# Create anonymous composite w = pywrap(o) wrapping the object o
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,16 @@ const PyInt = pyversion < v"3" ? Int : Clonglong
class A:
class B:
C = 1
@property
def D(self):
raise NotImplementedError
"""
A = py"A"
@test hasproperty(A, "B")
@test getproperty(A, "B") == py"A.B"
@test :B in propertynames(A)
@static if VERSION >= v"0.7-"
@test :D in propertynames(A.B)
@test A.B.C == 1
@test_throws KeyError A.X
end
Expand Down