Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable pylint execution on a section of code or function

I am using pylint 0.27 with python 2.7.3. Pylint has a known bug which hits when it analyses code having a .next() call. As given in http://www.logilab.org/122793 link, it fails with the given traceback.

I cannot change my python and pylint versions but I would like to workaround this problem by disabling pylint on the piece of code that has .next() call by adding a #pylint: MAGIC comment in my code.

I could find support for disabling pylint checking on a file using #pylint: skip-file but I am interested at doing this at function level or rather at line level.

Any other workarounds are also welcomed!

like image 757
Jatin Kumar Avatar asked Aug 27 '14 21:08

Jatin Kumar


2 Answers

You can accomplish this by adding the pylint comment as the first line of the function body like so:

def wont_raise_pylint():
  # pylint: disable=W0212
  some_module._protected_member()
  some_module._protected_member()

def will_still_raise_pylint():
  some_module._protected_member()
like image 194
Garrett Kadillak Avatar answered Oct 10 '22 10:10

Garrett Kadillak


Unfortunatly you won't be able to locally avoid the error you encounter.

One could expect to locate in the source code the offending piece of code, and then locally disable the involved message(s), but this won't work because it will still be run. This is because when locally disabling a message, the code detecting this message is run, only the message isn't be emitted in the end.

However, it may work if you globally disable this message (depending on the way it's implemented). In your case it seems unfortunatly that you would have to skip the whole 'logging' checker.

To sum up, to avoid your traceback you may either:

  • locally use pylint: skip-file, in which case every pylint's features will be activated but the whole offending file will be skipped

  • globally disable the 'logging' checker (--disable=logging), in which case the whole code (including the offending file) will be checked but without the 'logging' checker messages

like image 29
sthenault Avatar answered Oct 10 '22 10:10

sthenault