JuliaPy / JuliaPy/PyCall.jl

Misidentifying subclass of (python) list?

Open
#507 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
Julia
Stars
1.5k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

I'm trying to wrap a package that defines a class that subtypes python's `list` and adds methods. When I create one of these, it appears to be misidentified as a `list`, so the additional methods are not available.

The offending line seems to be conversions.jl:762:
```
# only handle PyList for now
return pyisinstance(o, @pyglobalobj :PyList_Type) ? Array : Union{}
```
Would it break things to check if `type(o) == list` rather than whether it's an instance?

Example:
```
Main> py"class MyClass1(list): # subclass of list
def fn(self):
print 'waldo was here'
"

Main> py"class MyClass2(): # NOT a subclass of list
def fn(self):
print 'waldo was here'
"

Main> c1 = py"MyClass1()" # misidentified as a list => Array
0-element Array{Any,1}

Main> c2 = py"MyClass2()"
PyObject <__main__.MyClass2 instance at 0x1a48492758>

Main> py"$c1.fn()"
ERROR: PyError (ccall(@pysym(:PyEval_EvalCode), PyPtr, (PyPtr, PyPtr, PyPtr), o, globals, locals)) <
type 'exceptions.AttributeError'>
AttributeError("'list' object has no attribute 'fn'",)
File "/Users/rjp/.julia/v0.6/PyCall/src/pyeval.jl", line 1, in
const Py_single_input = 256 # from Python.h

Stacktrace:
[1] pyerr_check at /Users/rjp/.julia/v0.6/PyCall/src/exception.jl:60 [inlined]
[2] pyerr_check at /Users/rjp/.julia/v0.6/PyCall/src/exception.jl:64 [inlined]
[3] macro expansion at /Users/rjp/.julia/v0.6/PyCall/src/exception.jl:84 [inlined]
[4] pyeval_(::String, ::PyCall.PyDict{String,PyCall.PyObject,false}, ::PyCall.PyDict{String,PyCall.
PyObject,false}, ::Int64, ::String) at /Users/rjp/.julia/v0.6/PyCall/src/pyeval.jl:23
[5] eval(::Module, ::Any) at ./boot.jl:235

Main> py"$c2.fn()"
waldo was here
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.