summaryrefslogtreecommitdiff
path: root/qutebrowser/utils/qtutils.py
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2022-08-25 08:41:16 +1200
committertoofar <toofar@spalge.com>2022-08-25 08:53:31 +1200
commitd20a58c26bf741846abeb5a2f3498a57ff6c6a4f (patch)
treee8d345fd858a061a9c08b6e2bdbe2aed6809fecc /qutebrowser/utils/qtutils.py
parentdfde9798074eb5ed192ff8ba074032e8a42b219a (diff)
downloadqutebrowser-d20a58c26bf741846abeb5a2f3498a57ff6c6a4f.tar.gz
qutebrowser-d20a58c26bf741846abeb5a2f3498a57ff6c6a4f.zip
Some Qt6 mypy fixesfeat/pyqt6_and_mypy
I'm running mypy like so: mypy --always-true=USE_PYQT6 --always-false=USE_PYQT5 --always-false=USE_PYSIDE2 --always-false=USE_PYSIDE6 --always-false=IS_QT5 --always-true=IS_QT6 qutebrowser/ And I just went down the output fixing easy stuff. Currently I'm getting 61 errors on Qt5 and 207 errors on Qt6 (down from 230 or so). I think the comparison ignores I removed are still needed on Qt5. I'm not sure how best to deal with situations that need to be ignored on one implementation and not on another. One way to do it would be to have alternate implementations per backend, but that could become a bit or a maintenance burden, see https://github.com/python/mypy/issues/8823 I'm also seeing some "Statement is unreachable" errors popping up which might be due to the same scenario. Many of the errors are related to there being no webkit on Qt6 so the webkit modules get resolved as ANY which makes all the # type: ignore messages be complained about. Not sure what we can do about that, possibly something from https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-exclude I see that Phil said we shouldn't need separate stubs for PyQt6. I'm still using them and haven't tried without yet.
Diffstat (limited to 'qutebrowser/utils/qtutils.py')
-rw-r--r--qutebrowser/utils/qtutils.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py
index 0bd9c94e8..66a4f679f 100644
--- a/qutebrowser/utils/qtutils.py
+++ b/qutebrowser/utils/qtutils.py
@@ -40,13 +40,14 @@ from qutebrowser.qt.core import (qVersion, QEventLoop, QDataStream, QByteArray,
QIODevice, QFileDevice, QSaveFile, QT_VERSION_STR,
PYQT_VERSION_STR, QObject, QUrl, QLibraryInfo)
from qutebrowser.qt.gui import QColor
+from qutebrowser.qt import machinery
try:
from qutebrowser.qt.webkit import qWebKitVersion
except ImportError: # pragma: no cover
qWebKitVersion = None # type: ignore[assignment] # noqa: N816
if TYPE_CHECKING:
from qutebrowser.qt.webkit import QWebHistory
- from qutebrowser.qt.webenginewidgets import QWebEngineHistory
+ from qutebrowser.qt.webenginecore import QWebEngineHistory
from qutebrowser.misc import objects
from qutebrowser.utils import usertypes, utils
@@ -186,13 +187,21 @@ def check_qdatastream(stream: QDataStream) -> None:
raise OSError(status_to_str[stream.status()])
-_QtSerializableType = Union[
- QObject,
- QByteArray,
- QUrl,
- 'QWebEngineHistory',
- 'QWebHistory'
-]
+if machinery.IS_QT5:
+ _QtSerializableType = Union[
+ QObject,
+ QByteArray,
+ QUrl,
+ 'QWebEngineHistory',
+ 'QWebHistory'
+ ]
+else:
+ _QtSerializableType = Union[
+ QObject,
+ QByteArray,
+ QUrl,
+ 'QWebEngineHistory',
+ ]
def serialize(obj: _QtSerializableType) -> QByteArray:
@@ -581,7 +590,7 @@ class LibraryPath(enum.Enum):
def library_path(which: LibraryPath) -> pathlib.Path:
"""Wrapper around QLibraryInfo.path / .location."""
- if hasattr(QLibraryInfo, "path"):
+ if machinery.IS_QT6:
# Qt 6
val = getattr(QLibraryInfo.LibraryPath, which.value)
ret = QLibraryInfo.path(val)