Skip to content

Files

Latest commit

 

History

History
33 lines (23 loc) · 791 Bytes

no-self-use.md

File metadata and controls

33 lines (23 loc) · 791 Bytes

Pattern: Use of instance method instead of static function

Issue: Instance method could be a static function

Description

The method does not make use of the class instance it gets passed. For clarity, it should be declared as a static method using the @staticmethod decorator.

Example of incorrect code:

class Foo(object):
    ...
    def bar(self, baz):
        ...
        return llama

Example of correct code:

class Foo(object):
    ...
    @staticmethod
    def bar(cls, baz):
        ...
        return llama

Further Reading