Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto ignore specific undefined variables in Pydev Eclipse

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:

eclipse_undef_variable

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.

like image 988
cseaton Avatar asked May 06 '10 01:05

cseaton


2 Answers

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.

like image 170
monkut Avatar answered Sep 23 '22 05:09

monkut


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

like image 23
Alex Martelli Avatar answered Sep 26 '22 05:09

Alex Martelli