Skip to content

Move no-self-use to optional checker #5502

@cdce8p

Description

@cdce8p

Related #5496

I recently came across code like this

class Parent:
    @staticmethod
    def get_email() -> str:
        return "test@test.com"

class Child(Parent):
    def __init__(self, email: str) -> None:
        self.email = email

    def get_email(self) -> str:
        return self.email


def func(x: Parent):
    print(x.get_email())

Although get_email is only ever called on an instance, the author choose to add the staticmethod decorator. I believe, just so pylint wouldn't complain about no-self-use.

With #5412 this will however now emit a arguments-differ warning on Child.get_email (with and without staticmethod).

Proposal
I would like to propose moving no-self-use to an optional checker.

Reason
Although this check might be helpful in some instances, usually not using self is no indication that a method should be static. As shown in the example, sometimes this leads to devs writing worse code just to satisfy pylint instead of adding pylint: disable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CheckersRelated to a checkerEnhancement ✨Improvement to a component

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions