CodeQL documentation

First parameter of a class method is not named ‘cls’

ID: py/not-named-cls
Kind: problem
Severity: recommendation
Precision: high
   - maintainability
   - readability
   - convention
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

The first parameter of a class method, a new method or any metaclass method should be called cls. This makes the purpose of the parameter clear to other developers.


Change the name of the first parameter to cls as recommended by the style guidelines in PEP 8.


In the example, the first parameter to make() is klass which should be changed to cls for ease of comprehension.

class Entry(object):
    def make(klass):
        return Entry()