7

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.

Community
  • 1
  • 1
cseaton
  • 662
  • 8
  • 19
  • 6
    I know this isn't what you wanted to do, but for completeness: You can get pydev to ignore these things by adding the comment #@UndefinedVariable after the line where os.symlink/os.readlink is. You probably already tried the Ctrl-1 solution, but I just thought I'd mention it. – Mattias Nilsson May 07 '10 at 11:34
  • 1
    That's the solution I'm currently using. – cseaton May 07 '10 at 13:20

3 Answers3

3

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.

monkut
  • 42,176
  • 24
  • 124
  • 155
  • Does pylint disable the normal pydev messages or is that just to ignore them in pylint? Also, I don't get a message id when mousing-over the "x" -- just 'undefined error from import: symlink'. – cseaton May 07 '10 at 09:49
  • pylint is somewhat of an add-on. You may be using the Pydev>Editor>Code Analysis feature. (Check if "Do code analysis?" is checked) I'm not familiar with how this feature works. – monkut May 10 '10 at 02:23
  • 3
    This is another sytnax: os.symlink(target, symlink) #@UndefinedVariable – AgDude Apr 23 '14 at 11:32
  • 1
    Meanwhile [pylint can use human readable message ids](http://stackoverflow.com/questions/13955361/list-of-pylint-human-readable-message-ids): `# pylint disable=undefined-variable`. – cfi Sep 16 '15 at 12:41
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...

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • 4
    I would rather not change my source code to deal with Pydev if at all possible. Also it appears that you have to do this at the method/function level for each undefined variable (doing this globally didn't work for me). Hopefully there are settings that I can add to my Pydev project file. – cseaton May 06 '10 at 02:43
0

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.

Lycha
  • 9,937
  • 3
  • 38
  • 43