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建议将方法更改为静态


- YouTube API v3 返回截断的观看记录 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01