Method should have "self" as first argument


Used when the first argument of a (instance) method has a name other than self.

This message belongs to the classes checker.


This is considered an error since this convention is so common that you shouldn't break it! This message enforces the corresponding Python convention. Python docs: Classes / Random Remarks offers a motivation for this convention:

Often, the first argument of a method is called self. This is nothing more than a convention: the name self has absolutely no special meaning to Python. Note, however, that by not following the convention your code may be less readable to other Python programmers, and it is also conceivable that a class browser program might be written that relies upon such a convention.

PEP 8: Function and Method Arguments states the convention more crisply as a rule:

Always use self for the first argument to instance methods.
Always use cls for the first argument to class methods.

For the corresponding message on class methods, see C0202.

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License