Skip to content

Commit

Permalink
mypy: Remove unneeded casts/ignores
Browse files Browse the repository at this point in the history
See #5368
  • Loading branch information
The-Compiler committed May 9, 2020
1 parent 2afda2e commit 80dc7dd
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 30 deletions.
4 changes: 2 additions & 2 deletions qutebrowser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def init(*, args: argparse.Namespace) -> None:
eventfilter.init()

log.init.debug("Connecting signals...")
q_app.focusChanged.connect(on_focus_changed) # type: ignore
q_app.focusChanged.connect(on_focus_changed)

_process_args(args)

for scheme in ['http', 'https', 'qute']:
QDesktopServices.setUrlHandler(
scheme, open_desktopservices_url) # type: ignore
scheme, open_desktopservices_url)

log.init.debug("Init done!")
crashsignal.crash_handler.raise_crashdlg()
Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/browser/browsertab.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ def send_event(self, evt: QEvent) -> None:
log.webview.warning("Unable to find event target!")
return

evt.posted = True
evt.posted = True # type: ignore
QApplication.postEvent(recipient, evt)

def navigation_blocked(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/browser/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def start(self, text, maximum):
self._progress.setMinimumDuration(500)
self._progress.setLabelText(text)
self._progress.setMaximum(maximum)
self._progress.setCancelButton(None) # type: ignore
self._progress.setCancelButton(None)
self._progress.show()
QApplication.processEvents()

Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/browser/webengine/webenginequtescheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from PyQt5.QtWebEngineCore import (QWebEngineUrlSchemeHandler,
QWebEngineUrlRequestJob)
try:
from PyQt5.QtWebEngineCore import QWebEngineUrlScheme # type: ignore
from PyQt5.QtWebEngineCore import QWebEngineUrlScheme
except ImportError:
# Added in Qt 5.12
QWebEngineUrlScheme = None
Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/browser/webengine/webenginetab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ def _connect_signals(self):

try:
# pylint: disable=unused-import
from PyQt5.QtWebEngineWidgets import ( # type: ignore
from PyQt5.QtWebEngineWidgets import (
QWebEngineClientCertificateSelection)
except ImportError:
pass
Expand Down
3 changes: 1 addition & 2 deletions qutebrowser/browser/webengine/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ def javaScriptPrompt(self, url, js_msg, default):
self.shutting_down],
escape_msg=escape_msg)
except shared.CallSuper:
return super().javaScriptPrompt( # type: ignore
url, js_msg, default)
return super().javaScriptPrompt(url, js_msg, default)

def javaScriptAlert(self, url, js_msg):
"""Override javaScriptAlert to use qutebrowser prompts."""
Expand Down
4 changes: 2 additions & 2 deletions qutebrowser/mainwindow/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def _on_show_prompts(self, question):
usertypes.PromptMode.alert: AlertPrompt,
}
klass = classes[question.mode]
prompt = typing.cast(_BasePrompt, klass(question))
prompt = klass(question)

log.prompt.debug("Displaying prompt {}".format(prompt))
self._prompt = prompt
Expand Down Expand Up @@ -707,7 +707,7 @@ def _init_fileview(self):
# Nothing selected initially
self._file_view.setCurrentIndex(QModelIndex())
# The model needs to be sorted so we get the correct first/last index
self._file_model.directoryLoaded.connect( # type: ignore
self._file_model.directoryLoaded.connect(
lambda: self._file_model.sort(0))

def accept(self, value=None, save=False):
Expand Down
13 changes: 4 additions & 9 deletions qutebrowser/mainwindow/tabbedbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,9 @@ def __init__(self, *, win_id, private, parent=None):
self._tab_insert_idx_left = 0
self._tab_insert_idx_right = -1
self.shutting_down = False
self.widget.tabCloseRequested.connect( # type: ignore
self.on_tab_close_requested)
self.widget.new_tab_requested.connect(self.tabopen)
self.widget.currentChanged.connect( # type: ignore
self._on_current_changed)
self.widget.tabCloseRequested.connect(self.on_tab_close_requested)
self.widget.new_tab_requested.connect(self.tabopen) # type: ignore
self.widget.currentChanged.connect(self._on_current_changed)
self.cur_fullscreen_requested.connect(self.widget.tabBar().maybe_hide)
self.widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

Expand Down Expand Up @@ -506,10 +504,7 @@ def undo(self):
newtab = self.widget.widget(0)
use_current_tab = False
else:
# FIXME:typing mypy thinks this is None due to @pyqtSlot
newtab = typing.cast(
browsertab.AbstractTab,
self.tabopen(background=False, idx=entry.index))
newtab = self.tabopen(background=False, idx=entry.index)

newtab.history.private_api.deserialize(entry.history)
self.widget.set_tab_pinned(newtab, entry.pinned)
Expand Down
6 changes: 3 additions & 3 deletions qutebrowser/mainwindow/tabwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def __init__(self, win_id, parent=None):
self.setStyle(TabBarStyle())
self.setTabBar(bar)
bar.tabCloseRequested.connect(self.tabCloseRequested) # type: ignore
bar.tabMoved.connect(functools.partial( # type: ignore
bar.tabMoved.connect(functools.partial(
QTimer.singleShot, 0, self.update_tab_titles))
bar.currentChanged.connect(self._on_current_changed) # type: ignore
bar.currentChanged.connect(self._on_current_changed)
bar.new_tab_requested.connect(self._on_new_tab_requested)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setDocumentMode(True)
Expand Down Expand Up @@ -544,7 +544,7 @@ def mousePressEvent(self, e):
idx = self.currentIndex()
elif action == 'close-last':
idx = self.count() - 1
self.tabCloseRequested.emit(idx) # type: ignore
self.tabCloseRequested.emit(idx)
return
super().mousePressEvent(e)

Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/misc/crashdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def show_error(self, text):
text: The paste text to show.
"""
error_dlg = ReportErrorDialog(text, self._paste_text, self)
error_dlg.finished.connect(self.finish) # type: ignore
error_dlg.finished.connect(self.finish)
error_dlg.show()

@pyqtSlot(str)
Expand Down
6 changes: 3 additions & 3 deletions qutebrowser/misc/guiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def __init__(self, what, *, verbose=False, additional_env=None,
self.args = None

self._proc = QProcess(self)
self._proc.errorOccurred.connect(self._on_error) # type: ignore
self._proc.errorOccurred.connect(self._on_error)
self._proc.errorOccurred.connect(self.error) # type: ignore
self._proc.finished.connect(self._on_finished) # type: ignore
self._proc.finished.connect(self._on_finished)
self._proc.finished.connect(self.finished) # type: ignore
self._proc.started.connect(self._on_started) # type: ignore
self._proc.started.connect(self._on_started)
self._proc.started.connect(self.started) # type: ignore

if additional_env is not None:
Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/misc/msgbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def msgbox(parent, title, text, *, icon, buttons=QMessageBox.Ok,
box.setIcon(icon)
box.setStandardButtons(buttons)
if on_finished is not None:
box.finished.connect(on_finished) # type: ignore
box.finished.connect(on_finished)
if plain_text:
box.setTextFormat(Qt.PlainText)
elif plain_text is not None:
Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def init_log(args: argparse.Namespace) -> None:
root.setLevel(logging.NOTSET)
logging.captureWarnings(True)
_init_py_warnings()
QtCore.qInstallMessageHandler(qt_message_handler) # type: ignore
QtCore.qInstallMessageHandler(qt_message_handler)
_log_inited = True


Expand Down
4 changes: 2 additions & 2 deletions qutebrowser/utils/urlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,13 @@ def safe_display_string(qurl: QUrl) -> str:
"""
ensure_valid(qurl)

host = qurl.host(QUrl.FullyEncoded) # type: ignore
host = qurl.host(QUrl.FullyEncoded)
if '..' in host: # pragma: no cover
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-60364
return '(unparseable URL!) {}'.format(qurl.toDisplayString())

for part in host.split('.'):
url_host = qurl.host(QUrl.FullyDecoded) # type: ignore
url_host = qurl.host(QUrl.FullyDecoded)
if part.startswith('xn--') and host != url_host:
return '({}) {}'.format(host, qurl.toDisplayString())

Expand Down

0 comments on commit 80dc7dd

Please sign in to comment.