Why does pycharm propose to change method to static

zerkms picture zerkms · May 9, 2014 · Viewed 95.8k times · Source

The new pycharm release (3.1.3 community edition) proposes to convert the methods that don't work with the current object's state to static.

enter image description here

What is the practical reason for that? Some kind of micro-performance(-or-memory)-optimization?

Answer

jolvi picture jolvi · May 9, 2014

PyCharm "thinks" that you might have wanted to have a static method, but you forgot to declare it to be static (using the @staticmethod decorator).

PyCharm proposes this because the method does not use self in its body and hence does not actually change the class instance. Hence the method could be static, i.e. callable without passing a class instance or without even having created a class instance.