summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2022-04-25 16:24:31 +1200
committertoofar <toofar@spalge.com>2022-07-03 16:51:04 +1200
commit6a9abd22764a14f86c625250952d2842bc9d34fe (patch)
tree987d3d490420ed6515387c9d851bd0ce4d806869
parent9eacfcb0dc914c9eb0c343b2adceab5048c1af76 (diff)
downloadqutebrowser-6a9abd22764a14f86c625250952d2842bc9d34fe.tar.gz
qutebrowser-6a9abd22764a14f86c625250952d2842bc9d34fe.zip
fix some string types and imports for mypy
The LibCST rename tool got a bit confused by imports done in `if TYPE_CHECKING:` blocks. For ones that were used it moved them out of those blocks. For ones that were only used in string type hints it half changed the imports and didn't updated the strings. A couple of instances were fixed in previous commits. These are the last few that mypy could see. Addressed manually. These fixers based on LibCST https://github.com/python-qt-tools/PyQt6-stubs/tree/main/fixes look like they could be useful. But they don't have any documentations of tests or anything. So it's much faster to fix these manually then to try to understand what all that is doing, if any of it is useful for us, extract it, test it etc.
-rw-r--r--qutebrowser/browser/webengine/notification.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/qutebrowser/browser/webengine/notification.py b/qutebrowser/browser/webengine/notification.py
index 55dcbff37..ce1ff342e 100644
--- a/qutebrowser/browser/webengine/notification.py
+++ b/qutebrowser/browser/webengine/notification.py
@@ -49,20 +49,18 @@ import itertools
import functools
import subprocess
from typing import Any, List, Dict, Optional, Iterator, Type, TYPE_CHECKING
-from qutebrowser.qt import widgets
if TYPE_CHECKING:
# putting these behind TYPE_CHECKING also means this module is importable
# on installs that don't have these
- from qutebrowser.qt import webenginewidgets, webenginecore, QWebEngineNotification
- from qutebrowser.qt import QWebEngineProfile
+ from qutebrowser.qt import webenginewidgets, webenginecore
from qutebrowser.config import config
from qutebrowser.misc import objects
from qutebrowser.utils import (
qtutils, log, utils, debug, message, objreg, resources,
)
-from qutebrowser.qt import gui, dbus, core, sip
+from qutebrowser.qt import widgets, gui, dbus, core, sip
bridge: Optional['NotificationBridgePresenter'] = None
@@ -153,7 +151,7 @@ class AbstractNotificationAdapter(core.QObject):
def present(
self,
- qt_notification: "QWebEngineNotification",
+ qt_notification: "webenginecore.QWebEngineNotification",
*,
replaces_id: Optional[int],
) -> int:
@@ -197,7 +195,7 @@ class NotificationBridgePresenter(core.QObject):
def __init__(self, parent: core.QObject = None) -> None:
super().__init__(parent)
- self._active_notifications: Dict[int, 'QWebEngineNotification'] = {}
+ self._active_notifications: Dict[int, 'webenginecore.QWebEngineNotification'] = {}
self._adapter: Optional[AbstractNotificationAdapter] = None
config.instance.changed.connect(self._init_adapter)
@@ -257,11 +255,11 @@ class NotificationBridgePresenter(core.QObject):
candidates["auto"] = candidates["libnotify"]
return candidates[setting]
- def install(self, profile: "QWebEngineProfile") -> None:
+ def install(self, profile: "webenginewidgets.QWebEngineProfile") -> None:
"""Set the profile to use this bridge as the presenter."""
profile.setNotificationPresenter(self.present)
- def present(self, qt_notification: "QWebEngineNotification") -> None:
+ def present(self, qt_notification: "webenginecore.QWebEngineNotification") -> None:
"""Show a notification using the configured adapter.
Lazily initializes a suitable adapter if none exists yet.
@@ -297,7 +295,7 @@ class NotificationBridgePresenter(core.QObject):
def _find_replaces_id(
self,
- new_notification: "QWebEngineNotification",
+ new_notification: "webenginecore.QWebEngineNotification",
) -> Optional[int]:
"""Find an existing notification to replace.
@@ -357,7 +355,7 @@ class NotificationBridgePresenter(core.QObject):
notification.click()
self._focus_first_matching_tab(notification)
- def _focus_first_matching_tab(self, notification: "QWebEngineNotification") -> None:
+ def _focus_first_matching_tab(self, notification: "webenginecore.QWebEngineNotification") -> None:
for win_id in objreg.window_registry:
tabbedbrowser = objreg.get("tabbed-browser", window=win_id, scope="window")
for idx, tab in enumerate(tabbedbrowser.widgets()):
@@ -437,7 +435,7 @@ class SystrayNotificationAdapter(AbstractNotificationAdapter):
def present(
self,
- qt_notification: "QWebEngineNotification",
+ qt_notification: "webenginecore.QWebEngineNotification",
*,
replaces_id: Optional[int],
) -> int:
@@ -499,7 +497,7 @@ class MessagesNotificationAdapter(AbstractNotificationAdapter):
def present(
self,
- qt_notification: "QWebEngineNotification",
+ qt_notification: "webenginecore.QWebEngineNotification",
*,
replaces_id: Optional[int],
) -> int:
@@ -518,7 +516,7 @@ class MessagesNotificationAdapter(AbstractNotificationAdapter):
def on_web_closed(self, _notification_id: int) -> None:
"""We can't close messages."""
- def _format_message(self, qt_notification: "QWebEngineNotification") -> str:
+ def _format_message(self, qt_notification: "webenginecore.QWebEngineNotification") -> str:
title = html.escape(qt_notification.title())
body = html.escape(qt_notification.message())
hint = "" if qt_notification.icon().isNull() else " (image not shown)"
@@ -559,7 +557,7 @@ class HerbeNotificationAdapter(AbstractNotificationAdapter):
def present(
self,
- qt_notification: "QWebEngineNotification",
+ qt_notification: "webenginecore.QWebEngineNotification",
*,
replaces_id: Optional[int],
) -> int:
@@ -580,7 +578,7 @@ class HerbeNotificationAdapter(AbstractNotificationAdapter):
def _message_lines(
self,
- qt_notification: "QWebEngineNotification",
+ qt_notification: "webenginecore.QWebEngineNotification",
) -> Iterator[str]:
"""Get the lines to display for this notification."""
yield qt_notification.title()
@@ -1006,7 +1004,7 @@ class DBusNotificationAdapter(AbstractNotificationAdapter):
def present(
self,
- qt_notification: "QWebEngineNotification",
+ qt_notification: "webenginecore.QWebEngineNotification",
*,
replaces_id: Optional[int],
) -> int: