Howto ignore specific undefined variables in Pydev Eclipse

泪湿孤枕 提交于 2019-12-21 04:44:05

问题


I'm writing a crossplatform python script on windows using Eclipse with the Pydev plugin. The script makes use of the os.symlink() and os.readlink() methods if the current platform isn't NT.

Since the os.symlink() and os.readlink() methods aren't available on the Windows platform Pydev flags them as undefined variables--like so:

Question:

Is there a way to ignore specific undefined variable name errors without modifying my source file?

edit: I found a way to ignore undefined variable errors from this answer on stackoverflow.
I'll leave the question open in case there is a way to solve this using project file or Pydev setting.


回答1:


I suspect pydev may have better, specific solutions, but what about just putting some code at the start of your program, such as:

if not hasattr(os, 'symlink'): os.symlink = None

Yeah, it's a hack, but, unless pydev does have specialized solutions (unfortunately I don't know of any, but then I'm no pydev expert;-), may be better than nothing...




回答2:


I use pydev + pylint.

With pylint you can add which messages to ignore in the Preferences>Pydev>Pylint>"Aggruments to pass to pylint" section.

--disable-msg=W0232,F0401

You can ignore messages in-line as well with comments:

os.symlink(target, symlink) # IGNORE:<MessageID> 

Mouse-over the "x" where the line numbers are to see the message id.




回答3:


I noticed PyDev doesn't recognize ZeroMQ constants so I struggled with the same problem.

I found PyDev has a settings option in Preferences > PyDev > Code Editor > Code Analysis : Undefined-tab. Just write symlink and readlink there (comma separated) to remove the errors.

Still not optimal, but good enough for now.



来源:https://stackoverflow.com/questions/2777880/howto-ignore-specific-undefined-variables-in-pydev-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!