From 56822836c5568ce6d5238e3b579770ebb8846b13 Mon Sep 17 00:00:00 2001 From: toofar Date: Sun, 11 Sep 2022 10:46:58 +1200 Subject: mypy: fix exec() type hints? PyQt5 exposes Enums and their corresponding QtFlags objects seperately, and for some reason they aren't interchangeable. ref https://github.com/python-qt-tools/PyQt5-stubs/issues/142 We could handle this by casting values back and forth between the enum value (for working with) and the flags value (for passing to methods), but this situation doesn't even exist with PyQt6, you can use everything as enums just fine. So I'm just adding ignore comments and making type definitions conditional. Not sure if this is the right thing to be doing or not. for b3cdb28d044 --- qutebrowser/utils/qtutils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 0bd9c94e8..87f74425e 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -455,6 +455,12 @@ class QtValueError(ValueError): super().__init__(err) +if machinery.IS_QT6: + _ProcessEventFlagType = QEventLoop.ProcessEventsFlag +else: + _ProcessEventFlagType = QEventLoop.ProcessEventsFlags + + class EventLoop(QEventLoop): """A thin wrapper around QEventLoop. @@ -468,8 +474,9 @@ class EventLoop(QEventLoop): def exec( self, - flags: QEventLoop.ProcessEventsFlag = - QEventLoop.ProcessEventsFlag.AllEvents + flags: _ProcessEventFlagType = ( + QEventLoop.ProcessEventsFlag.AllEvents # type: ignore[assignment] + ), ) -> int: """Override exec_ to raise an exception when re-running.""" if self._executing: -- cgit v1.2.3-54-g00ecf