First parameter of a class method is not named ‘cls’¶
ID: py/not-named-cls Kind: problem Security severity: Severity: recommendation Precision: high Tags: - maintainability - readability - convention - quality Query suites: - python-code-quality.qls - python-security-and-quality.qls Click to see the query in the CodeQL repository
The first parameter of a class method (including certain special methods such as __new__), or a method of a metaclass, should be named cls.
Recommendation¶
Ensure that the first parameter of class methods is named cls, as recommended by the style guidelines in PEP 8.
Example¶
In the following example, the first parameter of the class method make is named self instead of cls.
class Entry(object): @classmethod def make(self): return Entry() References¶
Python PEP 8: Function and method arguments.
Python Tutorial: Classes.
Python Docs: classmethod.