Issue
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.
Solution
(Spyder dev here) Sorry, it seems the completion library we use (called rope) can't do this kind of completions on dynamic classes and attributes.
You're welcome to ask on its mailing list about it, and if there's something we can do in our side, we'll be happy to help.
Answered By - Carlos Cordoba
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.