How to disable pylint no-self-use warning?
Solution 1
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):
...
...
Solution 2
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 :)
Related videos on Youtube
julka
Updated on July 09, 2022Comments
-
julka almost 2 years
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:
- How do I suppress warning (notice the
#pylint
comment)? or - How do I tell pylint that this is merely an interface (notice the
dummy_game
anddummy_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]
- How do I suppress warning (notice the
-
julka over 9 yearsAll three cases are ignored by pylint:
#pylint disable=R0201
and#pylint disable=no-self-use
before the class and both#pylint disable=R0201
with#pylint disable=no-self-use
. I prefer using full warning (no-self-use
) instead of code (R0201
), because it's easier to see what's supressed. -
Anshul Goyal over 9 years@julka I think you might be on an older version of pylint, try using
# pylint: disable-msg=R0201
instead. FWIW, on my system if I use# pylint: disable-msg=R0201
, it throws up another deprecation warning. -
julka over 9 yearsAgain ignored. Output of
pylint --version
is put into question. -
Anshul Goyal over 9 years@julka Just noticed in your post. You need to put that comment in a fresh line of its own, not in continuation of code.
-
julka over 9 yearsThanks for your help, it seems that I'm using an indeed older version of pylint. Quick check at pylint website said that current version is 1.4, while my system only has 1.2.1 (and is even built against python2). Now I only need to find how to tell Ubuntu package manager to download pylint 1.4 and build it against python3
-
Anshul Goyal over 9 years@julka So putting those pylint comments in a fresh line didn't work? In your example code currently, you put them in the same line as valid python code, so pylint won't catch them. I don't think this is a version specific issue.
-
julka over 9 yearsPylint did catch them: it said I have 0 comments (which is indeed true, if we exclude doc strings and pylint suppreses)
-
Anshul Goyal over 9 years@julka It caught them and still threw up that
no-self-use
error? incredible. -
julka over 9 yearsI wouldn't have asked the question otherwise. Yes, it caught (I think so) and yes, it throws (I see it).
-
julka over 9 yearskay, you were right, I finally managed to get latest pylint (following instructions here), it still throws
no-self-use
. -
julka over 9 yearsGod, I lacked colon: I used
pylint disable=no-self-use
when it should've beenpylint: disable=no-self-use
-
Anshul Goyal over 9 years@julka I see. I now realize that I was using the
:
in my examples, but didn't realize the difference in yours. Anyway, if that helped, don't forget to accept the answer. -
julka over 9 yearsBut yours didn't answer the question, best I can give is an upvote, and so I will when I'll have enough rep. Kay, they did, me stupey.