开发者

Undefined constants in eclipse

I'm using eclipse/aptana for python development. I have no issue with my python path config, autocomplete works fine with everything, however I am having the following problem:

When I have a "constant" in one of my classes and I try to access it, eclipse complains about "undefined variable from import" on the constant, eg

class Universe(object):
    ULTIMATE_ANSWER = 42

# in different module
# edit from: import Universe
from bigbang.models import Universe
print Universe.ULTIMATE_ANSWER

where Universe.ULTIMATE_ANSWER triggers the warning. Additionally, autocomplete works fine, so when I type Universe.x I do get all the constants proposed.

It's not an urgent issue, however it tends to become annoying, and might make you ignore actual errors.

Any idea on how to make eclipse behave on this one? :)

Edit: This only happens when importing the class in a another module.

Edit 2: In case it's not clear above, the code works, 开发者_开发技巧this is just about the warning that shouldn't be there... I have tried and replicated this on projects other than mine, both in eclipse and aptana with pydev.

Edit 3: As with the comments bellow, this is probably a bug in pydev. Submitted and waiting...


if, (see @Aix) you meant from mymodel import Universe:

Use ctrl+1 after Universe.ULTIMATE_ANSWER; You will be asked to add a comment to ignore that error.

You can also add your model as a forced builtin, prompting analyzis as in runtime (which you said, gave no error)


You don't import a class, you import a module.

If your module is called Universe (as is your class), then the fully qualified name of the variable is Universe.Universe.ULTIMATE_ANSWER.

If you defined the variable at the top level of the module (i.e. outside your class), then it would be called Universe.ULTIMATE_ANSWER:

# Universe module
ULTIMATE_ANSWER = 42
class Universe(object):
    pass

# in different module
import Universe
print Universe.ULTIMATE_ANSWER
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜