我尝试使用mypy检查使用 pyqt5 的项目。为了使我的问题更清楚,我创建了合成示例,而不是我的代码:
from PyQt5.QtCore import QDateTime
def date_to_string(date: QDateTime) -> str:
return date.toString("dd.MM.yyyy hh:mm:ss")
now = QDateTime.currentDateTime()
print(date_to_string(now))
当我运行mypy时,我得到:
~/.local/bin/mypy test.py
test.py:1: error: No library stub file for module 'PyQt5.QtCore'
test.py:1: note: (Stub files are from https://github.com/python/typeshed)
我发现/usr/share/qt/qsci/api/python/PyQt5.api
:
$ grep QDateTime /usr/share/qt/qsci/api/python/PyQt5.api | grep toString
PyQt5.QtCore.QDateTime.toString?4(Qt.DateFormat format=Qt.TextDate) -> QString
PyQt5.QtCore.QDateTime.toString?4(QString) -> QString
PyQt5.QtCore.QLocale.toString?4(QDateTime, QString) -> QString
PyQt5.QtCore.QLocale.toString?4(QDateTime, QLocale.FormatType format=QLocale.LongFormat) -> QString
这是mypy想要的吗?
我怎样才能告诉mypy使用/usr/share/qt/qsci/api/python/PyQt5.api
?
我也有/usr/lib/python3.6/site-packages/PyQt5/QtCore.pyi
,这个文件可能是mypy想要的吗?