Skip to main content

Sonar: Add Missing Positional Parameter for Instance and Class Methods


ImportanceReview GuidanceRequires Scanning Tool
LowMerge After Cursory ReviewYes (Sonar)

This codemod acts upon the following Sonar rules: python:S5719.

Python instance methods must be defined with self as the first argument. Likewise, class methods must have cls as the first argument. This codemod will add these arguments when the method/class method has no arguments defined.

Our changes look something like this:

 class MyClass:
- def instance_method():
+ def instance_method(self):

- def class_method():
+ def class_method(cls):

If you have feedback on this codemod, please let us know!


Why is this codemod marked as Merge After Cursory Review?

This change is safe and will prevent errors when calling on these instance or class methods..

Codemod Settings