Email [Python-projects] pylint: Rephrase "Method could be a function"?

from
subject
[Python-projects] pylint: Rephrase "Method could be a function"?
date
2006/02/23 18:15

Hi,

The refactoring hint "Method could be a function" issued by pylint can be misleading in some cases. For example, consider this scenario:

class Super:
        x = 1
        def method(self):
                print self.x

class Sub1(Super):
        def method(self):
                print 42

It is true that Sub1.method does not use "self", but it cannot be made a function because it is an overridden method and might be called on objects of which the type is unknown at the place they are called.

What is possible though, is change Sub1.method into a static method:

class Sub1(Super):
        @staticmethod
        def method():
                print 42

So maybe it's better to rephrase "Method could be a function" to "Method could be static" or "Method could be static or a function"?

Bye,
                Maarten