mypy: Switch to upstream stubs for PyQt6
They are getting much better
This commit is contained in:
parent
8da62bcbf4
commit
5a9027c54e
|
|
@ -11,7 +11,6 @@ mypy-extensions==1.0.0
|
|||
pluggy==1.2.0
|
||||
Pygments==2.15.1
|
||||
PyQt5-stubs==5.15.6.0
|
||||
PyQt6-stubs @ git+https://github.com/python-qt-tools/PyQt6-stubs.git@f623a641cd5cdff53342177e4fbbf9cae8172336
|
||||
tomli==2.0.1
|
||||
types-colorama==0.4.15.11
|
||||
types-docutils==0.20.0.1
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ lxml # For HTML reports
|
|||
diff-cover
|
||||
|
||||
PyQt5-stubs
|
||||
git+https://github.com/python-qt-tools/PyQt6-stubs.git
|
||||
types-PyYAML
|
||||
types-colorama
|
||||
types-Pygments
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ import contextlib
|
|||
import pathlib
|
||||
from typing import cast, Mapping, MutableSequence, Optional
|
||||
|
||||
from qutebrowser.qt import machinery
|
||||
from qutebrowser.qt.core import pyqtSlot, QUrl, QObject, pyqtSignal
|
||||
from qutebrowser.qt.widgets import QProgressDialog, QApplication
|
||||
from qutebrowser.qt.widgets import QProgressDialog, QApplication, QPushButton
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.api import cmdutils
|
||||
|
|
@ -54,7 +55,13 @@ class HistoryProgress:
|
|||
self._progress.setMaximum(0) # unknown
|
||||
self._progress.setMinimumDuration(0)
|
||||
self._progress.setLabelText(text)
|
||||
self._progress.setCancelButton(None)
|
||||
|
||||
no_button = None
|
||||
if machinery.IS_QT6:
|
||||
# FIXME:mypy PyQt6 stubs issue
|
||||
no_button = cast(QPushButton, None)
|
||||
|
||||
self._progress.setCancelButton(no_button)
|
||||
self._progress.setAutoClose(False)
|
||||
self._progress.show()
|
||||
QApplication.processEvents()
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ def _js_slot(*args):
|
|||
return self._error_con.callAsConstructor([e])
|
||||
# pylint: enable=protected-access
|
||||
|
||||
deco = pyqtSlot(*args, result=QJSValue)
|
||||
# FIXME:mypy PyQt6 stubs issue, passing type should work too
|
||||
deco = pyqtSlot(*args, result="QJSValue")
|
||||
return deco(new_method)
|
||||
return _decorator
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ class WebEngineRequest(interceptors.Request):
|
|||
"""QtWebEngine-specific request interceptor functionality."""
|
||||
|
||||
_WHITELISTED_REQUEST_METHODS = {
|
||||
# FIXME:mypy PyQt6-stubs issue?
|
||||
QByteArray(b'GET'), # type: ignore[call-overload,unused-ignore]
|
||||
QByteArray(b'HEAD'), # type: ignore[call-overload,unused-ignore]
|
||||
QByteArray(b'GET'),
|
||||
QByteArray(b'HEAD'),
|
||||
}
|
||||
|
||||
def __init__(self, *args, webengine_info, **kwargs):
|
||||
|
|
|
|||
|
|
@ -1109,8 +1109,7 @@ class DBusNotificationAdapter(AbstractNotificationAdapter):
|
|||
return None
|
||||
|
||||
bits = qimage.constBits().asstring(size)
|
||||
# FIXME:mypy PyQt6-stubs issue
|
||||
image_data.add(QByteArray(bits)) # type: ignore[call-overload,unused-ignore]
|
||||
image_data.add(QByteArray(bits))
|
||||
|
||||
image_data.endStructure()
|
||||
return image_data
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ from qutebrowser.qt.webenginecore import (QWebEngineUrlSchemeHandler,
|
|||
from qutebrowser.browser import qutescheme
|
||||
from qutebrowser.utils import log, qtutils
|
||||
|
||||
# FIXME:mypy PyQt6-stubs issue?
|
||||
_QUTE = QByteArray(b'qute') # type: ignore[call-overload,unused-ignore]
|
||||
_QUTE = QByteArray(b'qute')
|
||||
|
||||
|
||||
class QuteSchemeHandler(QWebEngineUrlSchemeHandler):
|
||||
|
|
|
|||
|
|
@ -299,7 +299,8 @@ class CompletionItemDelegate(QStyledItemDelegate):
|
|||
size = self._style.sizeFromContents(QStyle.ContentsType.CT_ItemViewItem, self._opt,
|
||||
docsize, self._opt.widget)
|
||||
qtutils.ensure_valid(size)
|
||||
return size + QSize(10, 3)
|
||||
# FIXME:mypy https://www.riverbankcomputing.com/pipermail/pyqt/2023-July/045400.html
|
||||
return size + QSize(10, 3) # type: ignore[call-arg,unused-ignore]
|
||||
|
||||
def paint(self, painter, option, index):
|
||||
"""Override the QStyledItemDelegate paint function.
|
||||
|
|
|
|||
|
|
@ -87,8 +87,6 @@ class EventFilter(QObject):
|
|||
True if the event should be filtered, False if it's passed through.
|
||||
"""
|
||||
ev_type = event.type()
|
||||
if machinery.IS_QT6:
|
||||
ev_type = cast(QEvent.Type, ev_type)
|
||||
|
||||
if self._log_qt_events:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -474,11 +474,7 @@ class ModeManager(QObject):
|
|||
QEvent.Type.ShortcutOverride:
|
||||
functools.partial(self._handle_keypress, dry_run=True),
|
||||
}
|
||||
ev_type = event.type()
|
||||
if machinery.IS_QT6:
|
||||
ev_type = cast(QEvent.Type, ev_type)
|
||||
|
||||
handler = handlers[ev_type]
|
||||
handler = handlers[event.type()]
|
||||
return handler(cast(QKeyEvent, event))
|
||||
|
||||
@cmdutils.register(instance='mode-manager', scope='window')
|
||||
|
|
|
|||
|
|
@ -259,6 +259,9 @@ class Command(misc.CommandLineEdit):
|
|||
else:
|
||||
raise utils.Unreachable("setText got called with invalid text "
|
||||
"'{}'!".format(text))
|
||||
# FIXME:mypy PyQt6 stubs issue
|
||||
if machinery.IS_QT6:
|
||||
text = cast(str, text)
|
||||
super().setText(text)
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
|
|
|
|||
|
|
@ -78,9 +78,7 @@ class HTTPClient(QObject):
|
|||
request = HTTPRequest(url)
|
||||
request.setHeader(QNetworkRequest.KnownHeaders.ContentTypeHeader,
|
||||
'application/x-www-form-urlencoded;charset=utf-8')
|
||||
# FIXME:mypy PyQt6-stubs issue
|
||||
reply = self._nam.post( # type: ignore[call-overload,unused-ignore]
|
||||
request, encoded_data)
|
||||
reply = self._nam.post(request, encoded_data)
|
||||
self._handle_reply(reply)
|
||||
|
||||
def get(self, url):
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
"""WORKAROUND for missing pyqtProperty typing, ported from PyQt5-stubs:
|
||||
|
||||
FIXME:mypy PyQt6-stubs issue
|
||||
https://github.com/python-qt-tools/PyQt5-stubs/blob/5.15.6.0/PyQt5-stubs/QtCore.pyi#L70-L111
|
||||
https://github.com/python-qt-tools/PyQt5-stubs/blob/5.15.6.0/PyQt5-stubs/QtCore.pyi#L68-L111
|
||||
"""
|
||||
|
||||
# flake8: noqa
|
||||
# pylint: disable=invalid-name,missing-class-docstring,too-many-arguments,redefined-builtin,unused-argument,import-error
|
||||
|
||||
import typing
|
||||
from PyQt6.QtCore import QObjectT, pyqtSignal
|
||||
from PyQt6.QtCore import QObject, pyqtSignal
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
QObjectT = typing.TypeVar("QObjectT", bound="QObject")
|
||||
|
||||
TPropertyTypeVal = typing.TypeVar("TPropertyTypeVal")
|
||||
|
||||
TPropGetter = typing.TypeVar(
|
||||
|
|
|
|||
|
|
@ -128,17 +128,20 @@ class VersionNumber:
|
|||
return NotImplemented
|
||||
return self._ver != other._ver
|
||||
|
||||
# FIXME:mypy type ignores below needed for PyQt5-stubs:
|
||||
# Unsupported left operand type for ... ("QVersionNumber")
|
||||
|
||||
def __ge__(self, other: 'VersionNumber') -> bool:
|
||||
return self._ver >= other._ver # type: ignore[operator]
|
||||
return self._ver >= other._ver # type: ignore[operator,unused-ignore]
|
||||
|
||||
def __gt__(self, other: 'VersionNumber') -> bool:
|
||||
return self._ver > other._ver # type: ignore[operator]
|
||||
return self._ver > other._ver # type: ignore[operator,unused-ignore]
|
||||
|
||||
def __le__(self, other: 'VersionNumber') -> bool:
|
||||
return self._ver <= other._ver # type: ignore[operator]
|
||||
return self._ver <= other._ver # type: ignore[operator,unused-ignore]
|
||||
|
||||
def __lt__(self, other: 'VersionNumber') -> bool:
|
||||
return self._ver < other._ver # type: ignore[operator]
|
||||
return self._ver < other._ver # type: ignore[operator,unused-ignore]
|
||||
|
||||
|
||||
class Unreachable(Exception):
|
||||
|
|
|
|||
1
tox.ini
1
tox.ini
|
|
@ -225,6 +225,7 @@ deps =
|
|||
-r{toxinidir}/misc/requirements/requirements-tests.txt
|
||||
-r{toxinidir}/misc/requirements/requirements-mypy.txt
|
||||
pyqt6: -r{toxinidir}/misc/requirements/requirements-pyqt-6.txt
|
||||
commands_pre = pip install --index-url https://www.riverbankcomputing.com/pypi/simple/ --pre --upgrade PyQt6
|
||||
commands =
|
||||
{envpython} -m mypy {env:QUTE_CONSTANTS_ARGS} qutebrowser {posargs}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue