Why does pycharm propose to change method to static(为什么pycharm建议将方法更改为静态)
问题描述
新的pycharm 版本(3.1.3 社区版)提出将不能处理当前对象状态的方法转换为静态.
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.
这样做的实际原因是什么?某种微性能(或内存)优化?
What is the practical reason for that? Some kind of micro-performance(-or-memory)-optimization?
推荐答案
PyCharm认为"你可能想要有一个静态方法,但你忘记声明它是静态的(使用@staticmethod
装饰器).
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 提出这一点是因为该方法在其主体中没有使用 self
,因此实际上并没有更改类实例.因此,该方法可以是静态的,即无需传递类实例或什至无需创建类实例即可调用.
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.
这篇关于为什么pycharm建议将方法更改为静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么pycharm建议将方法更改为静态


基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01