From 42f0ee36e3f789207fe3e2cc76efe95194e067db Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 29 Jun 2023 22:11:03 +0200 Subject: qt6 mypy: Remove PyQt5 type ignores --- qutebrowser/browser/browsertab.py | 2 +- qutebrowser/browser/commands.py | 2 +- qutebrowser/browser/hints.py | 11 +++++------ qutebrowser/browser/pdfjs.py | 5 ++--- qutebrowser/browser/shared.py | 6 ++---- qutebrowser/browser/webengine/notification.py | 2 +- qutebrowser/browser/webengine/webenginetab.py | 3 +-- qutebrowser/keyinput/keyutils.py | 3 +-- qutebrowser/keyinput/modeman.py | 2 +- qutebrowser/mainwindow/mainwindow.py | 2 +- qutebrowser/mainwindow/statusbar/command.py | 2 +- qutebrowser/mainwindow/tabbedbrowser.py | 4 ++-- qutebrowser/misc/ipc.py | 4 ++-- qutebrowser/utils/jinja.py | 2 +- qutebrowser/utils/urlutils.py | 4 ++-- 15 files changed, 24 insertions(+), 30 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 093380fc0..0fbd15c21 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -1332,7 +1332,7 @@ class AbstractTab(QWidget): try: qurl = self.url() as_unicode = QUrl.ComponentFormattingOption.EncodeUnicode - url = qurl.toDisplayString(as_unicode) # type: ignore[arg-type] + url = qurl.toDisplayString(as_unicode) except (AttributeError, RuntimeError) as exc: url = '<{}>'.format(exc.__class__.__name__) else: diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 84f217a38..750f28c9c 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -732,7 +732,7 @@ class CommandDispatcher: if key in config.val.url.yank_ignored_parameters: url_query.removeQueryItem(key) url.setQuery(url_query) - return url.toString(flags) # type: ignore[arg-type] + return url.toString(flags) @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('what', choices=['selection', 'url', 'pretty-url', diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 8fe75f271..5d7862e75 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -254,7 +254,7 @@ class HintActions: flags = QUrl.ComponentFormattingOption.FullyEncoded | QUrl.UrlFormattingOption.RemovePassword if url.scheme() == 'mailto': - flags |= QUrl.UrlFormattingOption.RemoveScheme # type: ignore[operator] + flags |= QUrl.UrlFormattingOption.RemoveScheme urlstr = url.toString(flags) new_content = urlstr @@ -276,7 +276,7 @@ class HintActions: def run_cmd(self, url: QUrl, context: HintContext) -> None: """Run the command based on a hint URL.""" - urlstr = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + urlstr = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) args = context.get_args(urlstr) commandrunner = runners.CommandRunner(self._win_id) commandrunner.run_safely(' '.join(args)) @@ -284,7 +284,7 @@ class HintActions: def preset_cmd_text(self, url: QUrl, context: HintContext) -> None: """Preset a commandline text based on a hint URL.""" flags = QUrl.ComponentFormattingOption.FullyEncoded - urlstr = url.toDisplayString(flags) # type: ignore[arg-type] + urlstr = url.toDisplayString(flags) args = context.get_args(urlstr) text = ' '.join(args) if text[0] not in modeparsers.STARTCHARS: @@ -331,13 +331,12 @@ class HintActions: 'QUTE_MODE': 'hints', 'QUTE_SELECTED_TEXT': str(elem), 'QUTE_SELECTED_HTML': elem.outer_xml(), - 'QUTE_CURRENT_URL': - context.baseurl.toString(flags), # type: ignore[arg-type] + 'QUTE_CURRENT_URL': context.baseurl.toString(flags), } url = elem.resolve_url(context.baseurl) if url is not None: - env['QUTE_URL'] = url.toString(flags) # type: ignore[arg-type] + env['QUTE_URL'] = url.toString(flags) try: userscripts.run_async(context.tab, cmd, *args, win_id=self._win_id, diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py index 737a9cc87..53387d634 100644 --- a/qutebrowser/browser/pdfjs.py +++ b/qutebrowser/browser/pdfjs.py @@ -95,8 +95,7 @@ def _generate_pdfjs_script(filename): url_query.addQueryItem('filename', filename) url.setQuery(url_query) - js_url = javascript.to_js( - url.toString(QUrl.ComponentFormattingOption.FullyEncoded)) # type: ignore[arg-type] + js_url = javascript.to_js(url.toString(QUrl.ComponentFormattingOption.FullyEncoded)) return jinja.js_environment.from_string(""" document.addEventListener("DOMContentLoaded", function() { @@ -245,7 +244,7 @@ def get_main_url(filename: str, original_url: QUrl) -> QUrl: query = QUrlQuery() query.addQueryItem('filename', filename) # read from our JS query.addQueryItem('file', '') # to avoid pdfjs opening the default PDF - urlstr = original_url.toString(QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + urlstr = original_url.toString(QUrl.ComponentFormattingOption.FullyEncoded) query.addQueryItem('source', urlstr) url.setQuery(query) return url diff --git a/qutebrowser/browser/shared.py b/qutebrowser/browser/shared.py index 92ed99584..562442b5a 100644 --- a/qutebrowser/browser/shared.py +++ b/qutebrowser/browser/shared.py @@ -229,9 +229,7 @@ def handle_certificate_error( # scheme might not match. is_resource = ( first_party_url.isValid() and - not request_url.matches( - first_party_url, - QUrl.UrlFormattingOption.RemoveScheme)) # type: ignore[arg-type] + not request_url.matches(first_party_url, QUrl.UrlFormattingOption.RemoveScheme)) if conf == 'ask' or conf == 'ask-block-thirdparty' and not is_resource: err_template = jinja.environment.from_string(""" @@ -261,7 +259,7 @@ def handle_certificate_error( error=error, ) urlstr = request_url.toString( - QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormattingOption.FullyEncoded) title = "Certificate error" try: diff --git a/qutebrowser/browser/webengine/notification.py b/qutebrowser/browser/webengine/notification.py index 1c608812e..76ba6b886 100644 --- a/qutebrowser/browser/webengine/notification.py +++ b/qutebrowser/browser/webengine/notification.py @@ -1180,7 +1180,7 @@ class DBusNotificationAdapter(AbstractNotificationAdapter): prefix = None elif self._capabilities.body_markup and self._capabilities.body_hyperlinks: href = html.escape( - origin_url.toString(QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + origin_url.toString(QUrl.ComponentFormattingOption.FullyEncoded) ) text = html.escape(urlstr, quote=False) prefix = f'{text}' diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 23dfcdb58..f1e3c1e8e 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -1437,8 +1437,7 @@ class WebEngineTab(browsertab.AbstractTab): title = self.title() title_url = QUrl(url) title_url.setScheme('') - title_url_str = title_url.toDisplayString( - QUrl.UrlFormattingOption.RemoveScheme) # type: ignore[arg-type] + title_url_str = title_url.toDisplayString(QUrl.UrlFormattingOption.RemoveScheme) if title == title_url_str.strip('/'): title = "" diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index a5ffd026a..0052cbb76 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -352,8 +352,7 @@ def _unset_modifier_bits( """ if machinery.IS_QT5: return cast(_ModifierType, modifiers & ~mask) - return Qt.KeyboardModifier( # type: ignore[unreachable] - modifiers.value & ~mask.value) + return Qt.KeyboardModifier(modifiers.value & ~mask.value) @dataclasses.dataclass(frozen=True, order=True) diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index dd849ebb6..5fdd7c30d 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -295,7 +295,7 @@ class ModeManager(QObject): has_modifier = event.modifiers() not in [ Qt.KeyboardModifier.NoModifier, Qt.KeyboardModifier.ShiftModifier, - ] # type: ignore[comparison-overlap] + ] is_non_alnum = has_modifier or not event.text().strip() forward_unbound_keys = config.cache['input.forward_unbound_keys'] diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index dccf9cea7..dcc04e0c0 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -580,7 +580,7 @@ class MainWindow(QWidget): refresh_window = self.isVisible() if hidden: modifiers = Qt.WindowType.CustomizeWindowHint | Qt.WindowType.NoDropShadowWindowHint - window_flags |= modifiers # type: ignore[assignment] + window_flags |= modifiers self.setWindowFlags(window_flags) if utils.is_mac and hidden and not qtutils.version_check('6.3', compiled=False): diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 84e026059..925ade795 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -276,7 +276,7 @@ class Command(misc.CommandLineEdit): 'prefix deleted') elif e.key() == Qt.Key.Key_Return: e.ignore() - elif e.key() == Qt.Key.Key_Insert and e.modifiers() == Qt.KeyboardModifier.ShiftModifier: # type: ignore[comparison-overlap] + elif e.key() == Qt.Key.Key_Insert and e.modifiers() == Qt.KeyboardModifier.ShiftModifier: try: text = utils.get_clipboard(selection=True, fallback=True) except utils.ClipboardError: diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index dbaffa2bf..b5d4bf652 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -221,8 +221,8 @@ class TabbedBrowser(QWidget): self._tab_insert_idx_right = -1 self.is_shutting_down = False self.widget.tabCloseRequested.connect(self.on_tab_close_requested) - self.widget.new_tab_requested.connect( # type: ignore[arg-type,unused-ignore] - self.tabopen) + self.widget.new_tab_requested.connect( + self.tabopen) # type: ignore[arg-type,unused-ignore] self.widget.currentChanged.connect(self._on_current_changed) self.cur_fullscreen_requested.connect(self.widget.tab_bar().maybe_hide) diff --git a/qutebrowser/misc/ipc.py b/qutebrowser/misc/ipc.py index c94c67b29..64ad1a260 100644 --- a/qutebrowser/misc/ipc.py +++ b/qutebrowser/misc/ipc.py @@ -276,12 +276,12 @@ class IPCServer(QObject): socket.errorOccurred.connect(self.on_error) - if socket.error() not in [ # type: ignore[operator] + if socket.error() not in [ QLocalSocket.LocalSocketError.UnknownSocketError, QLocalSocket.LocalSocketError.PeerClosedError ]: log.ipc.debug("We got an error immediately.") - self.on_error(socket.error()) # type: ignore[operator] + self.on_error(socket.error()) socket.disconnected.connect(self.on_disconnected) if socket.state() == QLocalSocket.LocalSocketState.UnconnectedState: log.ipc.debug("Socket was disconnected immediately.") diff --git a/qutebrowser/utils/jinja.py b/qutebrowser/utils/jinja.py index da8878aee..3e0fc7448 100644 --- a/qutebrowser/utils/jinja.py +++ b/qutebrowser/utils/jinja.py @@ -114,7 +114,7 @@ class Environment(jinja2.Environment): url = QUrl('qute://resource') url.setPath('/' + path) urlutils.ensure_valid(url) - urlstr = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + urlstr = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) return urlstr def _data_url(self, path: str) -> str: diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 5e8fbebe5..d8a440f35 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -548,7 +548,7 @@ def file_url(path: str) -> str: path: The absolute path to the local file """ url = QUrl.fromLocalFile(path) - return url.toString(QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + return url.toString(QUrl.ComponentFormattingOption.FullyEncoded) def data_url(mimetype: str, data: bytes) -> QUrl: @@ -639,7 +639,7 @@ def parse_javascript_url(url: QUrl) -> str: raise Error("URL contains unexpected components: {}" .format(url.authority())) - urlstr = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) # type: ignore[arg-type] + urlstr = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) urlstr = urllib.parse.unquote(urlstr) code = urlstr[len('javascript:'):] -- cgit v1.2.3-54-g00ecf