JuliaPy / JuliaPy/PyCall.jl

Misidentifying subclass of (python) list?

オープン
#507 コメント 5 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Julia
スター
1.5k
フォーク
186
PR マージ指標
30日以内にマージされた PR はありません

説明

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 <module>
    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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

conversions.jl:762 から始め、Julia 環境と Python 環境で issue の MyClass1/MyClass2 の例を再現します。PyCall が Python のリストサブクラスをどのように処理するかを追跡し、完成した変更によってサブクラスのメソッドへのアクセスが維持され、通常のリストも引き続き正しく処理されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
julia, python
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。