Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable pylint no-self-use warning?

I'm coding in Python3 and using pylint to keep my code clean.

I want to define something like interface class, so I could add more functionality in a clean and concise way, however, pylint gets in the way of this goal.

Here's a sample method:

def on_enter(self, dummy_game, dummy_player): #pylint disable=no-self-use
    """Defines effects when entering area."""
    return None

Here's pylint output:

R: 70, 4: Method could be a function (no-self-use)

The question is:

  1. How do I suppress warning (notice the #pylint comment)? or
  2. How do I tell pylint that this is merely an interface (notice the dummy_game and dummy_player

EDIT: Output of pylint --version:

pylint 1.2.1, 
astroid 1.1.1, common 0.61.0
Python 2.7.8 (default, Oct 20 2014, 15:05:19) 
[GCC 4.9.1]
like image 660
julka Avatar asked Jan 15 '15 14:01

julka


2 Answers

Turns out I was lacking colon :

I used
pylint disable=no-self-use
when it should have been
pylint: disable=no-self-use

Well, at least I will always have the latest (and the one built for python3) pylint from now on :)

like image 147
julka Avatar answered Sep 28 '22 07:09

julka


You are currently ignoring this as

def on_enter(self, dummy_game, dummy_player): #pylint disable=no-self-use
    ...

Instead do

# pylint: disable=R0201
def on_enter(self, dummy_game, dummy_player): 
    ...

Add a comment to your file like below

# pylint: disable=R0201

You can find the short codes mnemonics to for each of the warnings/errors on documentation here:

no-self-use (R0201):

Method could be a function Used when a method doesn’t use its bound instance, and so could be written as a function.

In case the whole file contains code for the interface only, you can put this at the top:

# pylint: disable=R0201
class SomeInterface(object):
    ...
    ...

In case you have other code as well, and want to disable this for the interface class only, you can enable the check again like

# pylint: disable=R0201
class SomeInterface(object):
    ...
    ...

# pylint: enable=R0201

class AnotherClass(object):
    ...
    ...
like image 39
Anshul Goyal Avatar answered Sep 28 '22 06:09

Anshul Goyal