Why does pycharm propose to change method to static

前端 未结 9 1607
面向向阳花
面向向阳花 2020-12-22 18:41

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.

9条回答
  •  没有蜡笔的小新
    2020-12-22 18:48

    Since you didn't refer to self in the bar method body, PyCharm is asking if you might have wanted to make bar static. In other programming languages, like Java, there are obvious reasons for declaring a static method. In Python, the only real benefit to a static method (AFIK) is being able to call it without an instance of the class. However, if that's your only reason, you're probably better off going with a top-level function - as note here.

    In short, I'm not one hundred percent sure why it's there. I'm guessing they'll probably remove it in an upcoming release.

提交回复
热议问题