self-or-cls-assignment (PLW0642)#
Derived from the Pylint linter.
This rule is unstable and in preview. The --preview
flag is required for use.
What it does#
Checks for assignment of self
and cls
in instance and class methods respectively.
Why is this bad?#
The identifiers self
and cls
are conventional in Python for the first argument of instance
methods and class methods, respectively.
Example#
class Versions:
def add(self, version):
self = version
@classmethod
def from_list(cls, versions):
cls = versions
Use instead: