0

after spending hours in googling, I learned a lot, but did not find any close topic to the following:

I am currently programming on dynamically created classes via a factory method. The reason is, that the method names should be populated according to a separate yaml-file. It comes down to this problem:

def create_class_with_dynamic_fuction_name(fun_name):
    def fun(self):
        print "Hello, I am fun"

    class X:
        pass

    setattr(X, fun_name, fun)
    return X

Kls1= create_class_with_dynamic_fuction_name('my_function_name')
kls1= Kls1()
kls1.my_function_name()

This code works. However, if you have this code in the editor of sypder (aka. Spider IDE, spyderlib), the autocomplete will not show my_function_name in its context box. Neither is it possible to inspect it via Ctrl+I for easy retrieval of the docstring-help.

The same problem arises, if a class is created with type(classname, (), clsdict). In that case, one only finds mro inside the autocomplete-context-menu.

Also I found, that it is not a problem of the closure pattern above. You can do

def create_class_with_static_function_name():
    def fun(self):
        print "Hello, I am fun"

    class X:
        my_function_name = fun

    return X

Kls2= create_class_with_static_function_name()
kls2= Kls2()
kls2.my_function_name()

In such case, the my_function_name shows correctly up, but it is not what I aimed for.

Would be glad to here any suggestions to accomplish dynamic creation of classes with dynamic method names, which are correctly handled in spyder's autocompletion within the editor window.

4

1 に答える 1

0

( Spyder dev here ) 申し訳ありませんが、私たちが使用している補完ライブラリ ( ropeと呼ばれる) は、動的クラスと属性に対してこの種の補完を行うことができないようです。

メーリング リストで質問してください。私たちにできることがあれば、喜んでお手伝いします。

于 2014-07-07T21:10:58.190 に答える