summaryrefslogtreecommitdiff
path: root/qutebrowser/utils/debug.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/debug.py
parentdfde9798074eb5ed192ff8ba074032e8a42b219a (diff)
downloadqutebrowser-feat/pyqt6_and_mypy.tar.gz
qutebrowser-feat/pyqt6_and_mypy.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/debug.py')
-rw-r--r--qutebrowser/utils/debug.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/qutebrowser/utils/debug.py b/qutebrowser/utils/debug.py
index ff6c3b9c2..f4f73dfc7 100644
--- a/qutebrowser/utils/debug.py
+++ b/qutebrowser/utils/debug.py
@@ -33,7 +33,7 @@ from qutebrowser.qt.core import Qt, QEvent, QMetaMethod, QObject, pyqtBoundSigna
from qutebrowser.utils import log, utils, qtutils, objreg
from qutebrowser.misc import objects
-from qutebrowser.qt import sip
+from qutebrowser.qt import sip, machinery
def log_events(klass: Type[QObject]) -> Type[QObject]:
@@ -99,7 +99,10 @@ def log_signals(obj: QObject) -> QObject:
return obj
-_EnumValueType = Union[sip.simplewrapper, int]
+if machinery.IS_QT5:
+ _EnumValueType = Union[sip.simplewrapper, int]
+else:
+ _EnumValueType = Union[sip.wrapper ,int]
def _qenum_key_python(
@@ -109,8 +112,10 @@ def _qenum_key_python(
"""New-style PyQt6: Try getting value from Python enum."""
if isinstance(value, enum.Enum) and value.name:
return value.name
+ assert isinstance(value, int)
# We got an int with klass passed: Try asking Python enum for member
+ assert klass
if issubclass(klass, enum.Enum):
try:
name = klass(value).name
@@ -131,7 +136,7 @@ def _qenum_key_qt(
# However, not every Qt enum value has a staticMetaObject
try:
meta_obj = base.staticMetaObject # type: ignore[union-attr]
- idx = meta_obj.indexOfEnumerator(klass.__name__)
+ idx = meta_obj.indexOfEnumerator(klass.__name__) # type: ignore[union-attr]
meta_enum = meta_obj.enumerator(idx)
key = meta_enum.valueToKey(int(value)) # type: ignore[arg-type]
if key is not None:
@@ -140,6 +145,7 @@ def _qenum_key_qt(
pass
# PyQt5: Try finding value match in class
+ assert klass
for name, obj in vars(base).items():
if isinstance(obj, klass) and obj == value:
return name
@@ -222,7 +228,7 @@ def qflags_key(base: Type[_EnumValueType],
for bit in bits:
# We have to re-convert to an enum type here or we'll sometimes get an
# empty string back.
- enum_value = klass(bit) # type: ignore[call-arg]
+ enum_value = klass(bit)
names.append(qenum_key(base, enum_value, klass))
return '|'.join(names)