如何让PyDev编辑器有选择地忽略错误?

时间:2021-07-15 17:27:28

I'm using PyDev under Eclipse to write some Jython code. I've got numerous instances where I need to do something like this:

我在Eclipse下使用PyDev来编写一些Jython代码。我有很多实例需要做这样的事情:

import com.work.project.component.client.Interface.ISubInterface as ISubInterface

The problem is that PyDev will always flag this as an error and say "Unresolved import: ISubInterface". The code works just fine, it's just that I'd rather not have these little white/red X-marks next to my code and have my Problems tab littered with these errors.

问题是PyDev总是将此标记为错误并说“Unresolved import:ISubInterface”。代码工作正常,只是我宁愿在我的代码旁边没有这些小的白色/红色X标记,并且我的“问题”选项卡中出现了这些错误。

Is there a way I can add a magic comment or something like that to the end of the line to make PyDev ignore the false error, similar to how you can sprinkle comments like "# pylint: disable-msg=E1101" to make PyLint ignore errors?

有没有办法我可以添加一个魔术评论或类似的东西到行的末尾,使PyDev忽略错误的错误,类似于你可以像“#pylint:disable-msg = E1101”这样的评论来使PyLint忽略错误?

Also, there's a possibility I'm just doing it wrong when it comes to using Java interfaces in Jython. In which case a little bit of guidance would be very much appreciated.

此外,在Jython中使用Java接口时,我有可能做错了。在这种情况下,我们非常感谢一点点的指导。

4 个解决方案

#1


55  

You can add a comment

您可以添加评论

#@UnresolvedImport
#@UnusedVariable

So your import becomes:

所以你的导入变成:

import com.work.project.component.client.Interface.ISubInterface as ISubInterface #@UnresolvedImport

That should remove the error/warning. There are other comments you can add as well.

这应该删除错误/警告。您还可以添加其他评论。

#2


29  

Add the hash character # at the end of the line then with the cursor on the flagged error, press Ctrl-1. One of the options in the menu will be something like @UndefinedVariable. Adding this comment will cause PyDev to ignore the error.

在行尾添加哈希字符#,然后将光标放在标记错误上,按Ctrl-1。菜单中的一个选项是@UndefinedVariable。添加此注释将导致PyDev忽略该错误。

#3


6  

You can make the ignore like the other posts suggest, but the real problem is that Pydev cannot find that class... If you add a .jar that contains that class to your PYTHONPATH it should be able to resolve it (or if you have a Java project that has that class, you should be able to mark that project as a Pydev project and add its bin folder to the project PYTHONPATH -- in which case that class should be found too).

您可以像其他帖子建议的那样进行忽略,但真正的问题是Pydev无法找到该类...如果您将包含该类的.jar添加到您的PYTHONPATH中,它应该能够解析它(或者如果您有如果是具有该类的Java项目,您应该能够将该项目标记为Pydev项目,并将其bin文件夹添加到项目PYTHONPATH中 - 在这种情况下也应该找到该类。

#4


-1  

It is not a PYTHONPATH issue. It is related to importing/using static class-internal members of a Java class. I am getting the same sort of thing all over the place e.g. when trying to use constants in java.awt.Color:

这不是PYTHONPATH问题。它与导入/使用Java类的静态类内部成员有关。我在整个地方得到同样的东西,例如当试图在java.awt.Color中使用常量时:

import java.awt.Color as Color
borderColor = Color.BLACK # get "Undefined variable from import: BLACK" error

There is no way I've found to import Color.BLACK in this case. Thanks to iceman for at least pointing out the #@UndefinedVariable flag. That helps a lot. Note also that this is NOT a jython problem, the code runs just fine. It's just an issue with PyDev.

在这种情况下,我无法找到导入Color.BLACK的方法。感谢iceman至少指出了#@ UndefinedVariable标志。这有很大帮助。另请注意,这不是一个jython问题,代码运行得很好。这只是PyDev的一个问题。

#1


55  

You can add a comment

您可以添加评论

#@UnresolvedImport
#@UnusedVariable

So your import becomes:

所以你的导入变成:

import com.work.project.component.client.Interface.ISubInterface as ISubInterface #@UnresolvedImport

That should remove the error/warning. There are other comments you can add as well.

这应该删除错误/警告。您还可以添加其他评论。

#2


29  

Add the hash character # at the end of the line then with the cursor on the flagged error, press Ctrl-1. One of the options in the menu will be something like @UndefinedVariable. Adding this comment will cause PyDev to ignore the error.

在行尾添加哈希字符#,然后将光标放在标记错误上,按Ctrl-1。菜单中的一个选项是@UndefinedVariable。添加此注释将导致PyDev忽略该错误。

#3


6  

You can make the ignore like the other posts suggest, but the real problem is that Pydev cannot find that class... If you add a .jar that contains that class to your PYTHONPATH it should be able to resolve it (or if you have a Java project that has that class, you should be able to mark that project as a Pydev project and add its bin folder to the project PYTHONPATH -- in which case that class should be found too).

您可以像其他帖子建议的那样进行忽略,但真正的问题是Pydev无法找到该类...如果您将包含该类的.jar添加到您的PYTHONPATH中,它应该能够解析它(或者如果您有如果是具有该类的Java项目,您应该能够将该项目标记为Pydev项目,并将其bin文件夹添加到项目PYTHONPATH中 - 在这种情况下也应该找到该类。

#4


-1  

It is not a PYTHONPATH issue. It is related to importing/using static class-internal members of a Java class. I am getting the same sort of thing all over the place e.g. when trying to use constants in java.awt.Color:

这不是PYTHONPATH问题。它与导入/使用Java类的静态类内部成员有关。我在整个地方得到同样的东西,例如当试图在java.awt.Color中使用常量时:

import java.awt.Color as Color
borderColor = Color.BLACK # get "Undefined variable from import: BLACK" error

There is no way I've found to import Color.BLACK in this case. Thanks to iceman for at least pointing out the #@UndefinedVariable flag. That helps a lot. Note also that this is NOT a jython problem, the code runs just fine. It's just an issue with PyDev.

在这种情况下,我无法找到导入Color.BLACK的方法。感谢iceman至少指出了#@ UndefinedVariable标志。这有很大帮助。另请注意,这不是一个jython问题,代码运行得很好。这只是PyDev的一个问题。