Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Mypy显示“;可调用的。。。“没有属性”;“连接”;在PyQT中的每个connect()上_Python_Pyqt5_Mypy - Fatal编程技术网

Python Mypy显示“;可调用的。。。“没有属性”;“连接”;在PyQT中的每个connect()上

Python Mypy显示“;可调用的。。。“没有属性”;“连接”;在PyQT中的每个connect()上,python,pyqt5,mypy,Python,Pyqt5,Mypy,使用PyQt5编写代码,使用mypy查找类型错误。但mypy在每个connect()上都会发现错误,例如在以下简单文件上: from PyQt5 import QtWidgets class TestClass(QtWidgets.QDialog): def __init__(self) -> None: super().__init__() self.accepted.connect(self.accept) 我有mypy错误:1.py:6:e

使用PyQt5编写代码,使用mypy查找类型错误。但mypy在每个connect()上都会发现错误,例如在以下简单文件上:

from PyQt5 import QtWidgets

class TestClass(QtWidgets.QDialog):
    def __init__(self) -> None:
        super().__init__()
        self.accepted.connect(self.accept)
我有mypy错误:
1.py:6:error:“Callable[],None]”没有属性“connect”


有没有办法解释mypy的正确代码?我不想对他使用“忽略”注释…

安装
PyQt5存根
为PyQt5键入存根

>mypy test.py
test.py:6: error: "Callable[[], None]" has no attribute "connect"
Found 1 error in 1 file (checked 1 source file)

>pip install PyQt5-stubs
Collecting PyQt5-stubs
  Downloading PyQt5_stubs-5.15.2.0-py3-none-any.whl (371 kB)
     |████████████████████████████████| 371 kB 3.3 MB/s
Installing collected packages: PyQt5-stubs
Successfully installed PyQt5-stubs-5.15.2.0

>mypy test.py
Success: no issues found in 1 source file

你确定那不是一个可调用的吗?它应该是可调用的,这是一个信号,我正在连接到一个插槽。你在PyQt中使用什么类型的存根?似乎QDialog应该具有声明
QDialog.accepted
pyqtSignal
而不是
可调用的类型存根。(或者您的
TestClass
是否尝试将
接受的
属性作为方法“覆盖”?@Samwise如何检查我的存根?我没有重写任何东西,这是一个完整的代码来说明“问题”