Type annotations of objects to the correct class in Python/Eclipse
I'm using Eclipse for developing some Python based application.
Very often I pass some class object to methods. So how can I say to the eclipse that this particular variable 开发者_如何转开发is of type Class A. For ex.
def foo(var1,var2):
''' var1 is of type Class A, and var2 is of type Class B'''
var1.a = 10
var2.b = 'xyz'
I can use all these ways, problems is that Eciplse can't give the variable hints for all these member variables for Class A
and Class B
. I've to go and check the member variables manually. This is very hectic and error prone. Is there any way I can tell eclipse/python that var1
is of type Class A
and var2
is of type class B
?
There exists no such thing as type casting in Python. There's type coercion that happens in arithmetic expressions, e.g., but that's something different. As I explained here, there's no sensible way for Eclipse to do what you want it do do. Since Python 3 there are type annotations in function definitions, as propopsed in PEP-3107, which may or may not be used in the future by programs like PyDev.
Until then, instead of fighting duck typing, you should embrace its power.
I got the same issue ... as far as I've been searching, you can't do that!
Typing Casting in Python Question
精彩评论