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

发布于 2024-08-11 03:36:03 字数 451 浏览 5 评论 0原文

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

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

问题是 PyDev 总是将其标记为错误并说“未解析的导入:ISubInterface”。代码工作得很好,只是我不想在我的代码旁边有这些白色/红色的小 X 标记,并且我的“问题”选项卡上到处都是这些错误。

有没有一种方法可以在行尾添加一个神奇的注释或类似的东西来使 PyDev 忽略错误错误,类似于如何撒上像“# pylint:disable-msg=E1101”这样的注释来使 PyLint 忽略错误?

另外,当涉及到在 Jython 中使用 Java 接口时,我可能做错了。在这种情况下,我们将非常感谢您的一点指导。

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

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.

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

落叶缤纷 2024-08-18 03:36:03

您可以添加评论,

#@UnresolvedImport
#@UnusedVariable

这样您的导入就会变成:

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

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

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.

颜漓半夏 2024-08-18 03:36:03

在行末尾添加井号字符 #,然后将光标放在标记的错误上,按 Ctrl-1。菜单中的选项之一类似于@UndefinedVariable。添加此注释将导致 PyDev 忽略该错误。

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.

哭了丶谁疼 2024-08-18 03:36:03

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

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).

触ぅ动初心 2024-08-18 03:36:03

这不是 PYTHONPATH 问题。它与导入/使用 Java 类的静态类内部成员有关。我到处都遇到同样的事情,例如当尝试在 java.awt.Color 中使用常量时:

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

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

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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文