eclipse 中未定义的常量
我正在使用 eclipse/aptana 进行 python 开发。 我的 python 路径配置没有问题,自动完成功能对所有内容都可以正常工作,但是我遇到了以下问题:
当我的一个类中有一个“常量”并且我尝试访问它时,Eclipse 会抱怨 ” undefined variable from import" 常量,例如,
class Universe(object):
ULTIMATE_ANSWER = 42
# in different module
# edit from: import Universe
from bigbang.models import Universe
print Universe.ULTIMATE_ANSWER
Universe.ULTIMATE_ANSWER 触发警告的地方。 此外,自动完成工作正常,因此当我输入 Universe.x 时,我确实得到了建议的所有常量。
这不是一个紧迫的问题,但它往往会变得烦人,并且可能会让您忽略实际的错误。
关于如何让 Eclipse 在此行为上有任何想法吗? :)
编辑: 仅当在另一个模块中导入该类时才会发生这种情况。
编辑2: 如果上面不清楚,代码可以工作,这只是关于不应该出现的警告...... 我已经尝试并在我以外的项目上复制了这个,包括在 eclipse 和 aptana 中使用 pydev。
编辑3: 与下面的评论一样,这可能是 pydev 中的一个错误。已提交,等待中...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果,(参见@Aix)您的意思是
from mymodel import Universe
:在
Universe.ULTIMATE_ANSWER
之后使用ctrl+1;系统会要求您添加注释以忽略该错误。您还可以将模型添加为强制内置模型,从而在运行时提示分析(您所说的没有给出错误)
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)
您不是
导入
一个类,而是导入一个模块。如果您的模块名为
Universe
(与您的类一样),则变量的完全限定名称为Universe.Universe.ULTIMATE_ANSWER
。如果您在模块的顶层(即在类之外)定义了变量,那么它将被称为Universe.ULTIMATE_ANSWER:
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 isUniverse.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
: