Class Method First Parameter Should Be `cls`
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: class-method-first-arg-name
Section titled “Sourcery refactoring id: class-method-first-arg-name”Description:
Section titled “Description:”Suggests that class methods should rename their first parameter to cls.
Before:
Section titled “Before:”class Chicken: @classmethod def from_egg(new, egg): with egg.hatch() as chick: return new(chick)After:
Section titled “After:”class Chicken: @classmethod def from_egg(cls, egg): with egg.hatch() as chick: return cls(chick)Explanation:
Section titled “Explanation:”This is both a very strong convention in Python and an explicit entry in PEP-8. Adhering to it improves code consistency and makes it easier for developers to understand the intention of your code.
See also instance-method-first-arg-name