Pylint 误报“<class 'RuntimeError'>:包装的 C/C++ QApplication 类型的对象已被删除”
Pylint false positive "<class 'RuntimeError'>: wrapped C/C++ object of type QApplication has been deleted"
我已经使用我的编码环境一段时间了。这个问题最近在 pylint 或 VS-code 的一些升级后发生。
我的设置是:
VS-Code + Python 3.7(anaconda) + pylint 2.5.0
我在 VS-Code 中使用的一些扩展是:Anaconda Extension Pack,Qt for Python
这是重现此问题所需的最少代码:
#!/usr/bin/env python3
"""
A demo for pylint
"wrapped C/C++ object of type QApplication has been deleted"
false positive
"""
import sys
from PyQt5 import QtWidgets
class Window(QtWidgets.QMainWindow):
"""A simple window"""
def __init__(self):
super(Window, self).__init__()
self.variable = 1 # This line triggers the alarm.
self.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
newWindow = Window()
sys.exit(app.exec_())
显然,没有任何真正的问题。上面的代码 运行 就好了。
与此同时,pylint 不断抱怨:
已包装 C/C++ QApplication 类型的对象已被删除
通常我不会打扰。但是,此错误会阻止 pylint 迭代。
有谁知道是什么让 pylint 不开心?
PS,这是我的 VS-Code
的 settings.json
{
"editor.renderWhitespace": "selection",
"editor.tabCompletion": "on",
"files.eol": "\n",
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"window.autoDetectHighContrast": false,
"window.zoomLevel": 0,
"git.autofetch": true,
"python.dataScience.notebookFileRoot": "${fileDirname}",
"python.terminal.executeInFileDir": true,
"python.linting.pylintEnabled": true,
"python.linting.pycodestyleEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=PyQt5",
"--generated-members=numpy.*, torch.*, PyQt5.*",
"--disable=invalid-name, protected-access, E1102"
],
"python.dataScience.sendSelectionToInteractiveWindow": false,
"workbench.colorTheme": "Monokai",
}
我刚刚设置了一个干净的虚拟机,并对这些包的不同版本进行了快速测试。
原来这个问题是从pylint 2.5.0开始引入的。
Pylint 2.4.4 没问题。
与其说是问题,不如说是错误。无论如何..
我在 Github 上开了一个问题,去看看你们 运行 是否遇到过类似的问题:
#3617
它可能也与astroid有关。我真的不在乎,我会坚持使用 2.4.4,直到出现更好的解决方案。
这确实是 astroid v2.4.0 的一个错误,自 astroid v2.4.1 与 Pylint v2.5.2 配对以来已修复。
我已经使用我的编码环境一段时间了。这个问题最近在 pylint 或 VS-code 的一些升级后发生。
我的设置是:
VS-Code + Python 3.7(anaconda) + pylint 2.5.0
我在 VS-Code 中使用的一些扩展是:Anaconda Extension Pack,Qt for Python
这是重现此问题所需的最少代码:
#!/usr/bin/env python3
"""
A demo for pylint
"wrapped C/C++ object of type QApplication has been deleted"
false positive
"""
import sys
from PyQt5 import QtWidgets
class Window(QtWidgets.QMainWindow):
"""A simple window"""
def __init__(self):
super(Window, self).__init__()
self.variable = 1 # This line triggers the alarm.
self.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
newWindow = Window()
sys.exit(app.exec_())
显然,没有任何真正的问题。上面的代码 运行 就好了。
与此同时,pylint 不断抱怨:
已包装 C/C++ QApplication 类型的对象已被删除
通常我不会打扰。但是,此错误会阻止 pylint 迭代。
有谁知道是什么让 pylint 不开心?
PS,这是我的 VS-Code
的 settings.json{
"editor.renderWhitespace": "selection",
"editor.tabCompletion": "on",
"files.eol": "\n",
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"window.autoDetectHighContrast": false,
"window.zoomLevel": 0,
"git.autofetch": true,
"python.dataScience.notebookFileRoot": "${fileDirname}",
"python.terminal.executeInFileDir": true,
"python.linting.pylintEnabled": true,
"python.linting.pycodestyleEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=PyQt5",
"--generated-members=numpy.*, torch.*, PyQt5.*",
"--disable=invalid-name, protected-access, E1102"
],
"python.dataScience.sendSelectionToInteractiveWindow": false,
"workbench.colorTheme": "Monokai",
}
我刚刚设置了一个干净的虚拟机,并对这些包的不同版本进行了快速测试。 原来这个问题是从pylint 2.5.0开始引入的。 Pylint 2.4.4 没问题。
与其说是问题,不如说是错误。无论如何..
我在 Github 上开了一个问题,去看看你们 运行 是否遇到过类似的问题: #3617 它可能也与astroid有关。我真的不在乎,我会坚持使用 2.4.4,直到出现更好的解决方案。
这确实是 astroid v2.4.0 的一个错误,自 astroid v2.4.1 与 Pylint v2.5.2 配对以来已修复。