python - 如何在类型化属性的类定义中使 pycharm 的自动完成工作?
问题描述
当我在 init 语句中设置对象的类型时,自动完成在 init 语句中起作用:
from PyQt5.QtWidgets import QLabel
class TestAutoComplete:
def __init__(self):
self.testLabel: QLabel
self.testLabel.
然后,当我想在另一个函数中自动完成相同的变量时,它不起作用:
from PyQt5.QtWidgets import QLabel
class TestAutoComplete:
def __init__(self):
self.testLabel: QLabel
def otherFunction(self):
self.testLabel.
如何为属性设置一次类型,然后在每个类函数定义中自动完成?
亲切的问候巴斯蒂安
解决方案
似乎我偶然找到了答案。您必须键入一个类变量:
from PyQt5.QtWidgets import QLabel
class TestAutoComplete:
testLabel: QLabel
def __init__(self):
pass
def otherFunction(self):
self.testLabel.
这对我来说似乎很奇怪。我是一个 python 初学者,但我想已经明白这个屏幕截图中的 testLabel 是一个类变量,只能通过 TestAutoComplete.testLabel 而不是通过 self.testLabel 访问。这可能是 pycharm 自动完成中的错误吗?
推荐阅读
- reactjs - 如何构建一个 create-react-app 项目
- spring-boot - 将生成和下载文件时对内存的影响降至最低
- performance - 理论标量整数性能 KabyLake
- css - 谷歌地方自动完成的样式不起作用
- ssl - 以编程方式测试与特定网站端口 443 的成功出站连接的最佳方法是什么?
- java - 使用 jsoup java 排除“无图片 url”
- jenkins - Jenkins管道httpRequest给出NotSerializableException
- python - 如何使用打字模块创建自定义类型?
- c# - 使用 TMDb c# api 将信息传递给 TextBlock
- git - 提交了一个拉取请求,已合并,现在我需要更新我的 fork