diff options
author | toofar <toofar@spalge.com> | 2022-09-11 10:46:58 +1200 |
---|---|---|
committer | toofar <toofar@spalge.com> | 2022-09-11 17:22:50 +1200 |
commit | 56822836c5568ce6d5238e3b579770ebb8846b13 (patch) | |
tree | 17cc1a3b64db1bede0f54ee99a65c48c664d7f65 | |
parent | 4647125172bfa10bd1b5624c34bf4400011b6ada (diff) | |
download | qutebrowser-56822836c5568ce6d5238e3b579770ebb8846b13.tar.gz qutebrowser-56822836c5568ce6d5238e3b579770ebb8846b13.zip |
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
-rw-r--r-- | qutebrowser/utils/qtutils.py | 11 |
1 files 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: |