Fix types in @pyqtSlot decorations

PyQt 5.5 enforces correct type signatures, and there were a lot of
places where we were simply wrong, causing qutebrowser to not start at
all...
This commit is contained in:
Florian Bruhin 2016-04-26 20:20:29 +02:00
parent da24e43fa5
commit 37b5f49c85
12 changed files with 20 additions and 16 deletions

View File

@ -231,7 +231,7 @@ class DownloadItemStats(QObject):
else: else:
return remaining_bytes / avg return remaining_bytes / avg
@pyqtSlot(int, int) @pyqtSlot('qint64', 'qint64')
def on_download_progress(self, bytes_done, bytes_total): def on_download_progress(self, bytes_done, bytes_total):
"""Update local variables when the download progress changed. """Update local variables when the download progress changed.
@ -650,7 +650,7 @@ class DownloadItem(QObject):
except OSError as e: except OSError as e:
self._die(e.strerror) self._die(e.strerror)
@pyqtSlot(int) @pyqtSlot('QNetworkReply::NetworkError')
def on_reply_error(self, code): def on_reply_error(self, code):
"""Handle QNetworkReply errors.""" """Handle QNetworkReply errors."""
if code == QNetworkReply.OperationCanceledError: if code == QNetworkReply.OperationCanceledError:

View File

@ -253,7 +253,7 @@ class NetworkManager(QNetworkAccessManager):
except KeyError: except KeyError:
pass pass
@pyqtSlot('QNetworkReply', 'QAuthenticator') @pyqtSlot('QNetworkReply*', 'QAuthenticator*')
def on_authentication_required(self, reply, authenticator): def on_authentication_required(self, reply, authenticator):
"""Called when a website needs authentication.""" """Called when a website needs authentication."""
user, password = None, None user, password = None, None
@ -286,7 +286,7 @@ class NetworkManager(QNetworkAccessManager):
authenticator.setUser(user) authenticator.setUser(user)
authenticator.setPassword(password) authenticator.setPassword(password)
@pyqtSlot('QNetworkProxy', 'QAuthenticator') @pyqtSlot('QNetworkProxy', 'QAuthenticator*')
def on_proxy_authentication_required(self, proxy, authenticator): def on_proxy_authentication_required(self, proxy, authenticator):
"""Called when a proxy needs authentication.""" """Called when a proxy needs authentication."""
proxy_id = ProxyId(proxy.type(), proxy.hostName(), proxy.port()) proxy_id = ProxyId(proxy.type(), proxy.hostName(), proxy.port())

View File

@ -288,7 +288,7 @@ class BrowserPage(QWebPage):
window=self._win_id) window=self._win_id)
download_manager.get_request(req, page=self) download_manager.get_request(req, page=self)
@pyqtSlot('QNetworkReply') @pyqtSlot('QNetworkReply*')
def on_unsupported_content(self, reply): def on_unsupported_content(self, reply):
"""Handle an unsupportedContent signal. """Handle an unsupportedContent signal.
@ -334,7 +334,7 @@ class BrowserPage(QWebPage):
else: else:
self.error_occurred = False self.error_occurred = False
@pyqtSlot('QWebFrame', 'QWebPage::Feature') @pyqtSlot('QWebFrame*', 'QWebPage::Feature')
def on_feature_permission_requested(self, frame, feature): def on_feature_permission_requested(self, frame, feature):
"""Ask the user for approval for geolocation/notifications.""" """Ask the user for approval for geolocation/notifications."""
options = { options = {
@ -439,7 +439,7 @@ class BrowserPage(QWebPage):
if 'scroll-pos' in data and frame.scrollPosition() == QPoint(0, 0): if 'scroll-pos' in data and frame.scrollPosition() == QPoint(0, 0):
frame.setScrollPosition(data['scroll-pos']) frame.setScrollPosition(data['scroll-pos'])
@pyqtSlot(str) @pyqtSlot(usertypes.ClickTarget)
def on_start_hinting(self, hint_target): def on_start_hinting(self, hint_target):
"""Emitted before a hinting-click takes place. """Emitted before a hinting-click takes place.

View File

@ -352,7 +352,7 @@ class WebView(QWebView):
frame = self.page().mainFrame() frame = self.page().mainFrame()
frame.javaScriptWindowObjectCleared.connect(self.add_js_bridge) frame.javaScriptWindowObjectCleared.connect(self.add_js_bridge)
@pyqtSlot(QWebFrame) @pyqtSlot()
def add_js_bridge(self): def add_js_bridge(self):
"""Add the javascript bridge for qute:... pages.""" """Add the javascript bridge for qute:... pages."""
frame = self.sender() frame = self.sender()

View File

@ -258,6 +258,7 @@ class CommandRunner(QObject):
result.cmd.run(self._win_id, args) result.cmd.run(self._win_id, args)
@pyqtSlot(str, int) @pyqtSlot(str, int)
@pyqtSlot(str)
def run_safely(self, text, count=None): def run_safely(self, text, count=None):
"""Run a command and display exceptions in the statusbar.""" """Run a command and display exceptions in the statusbar."""
try: try:

View File

@ -26,6 +26,7 @@ from qutebrowser.config import config, configdata
from qutebrowser.utils import objreg, log from qutebrowser.utils import objreg, log
from qutebrowser.commands import cmdutils from qutebrowser.commands import cmdutils
from qutebrowser.completion.models import base from qutebrowser.completion.models import base
from qutebrowser.mainwindow import mainwindow
class CommandCompletionModel(base.BaseCompletionModel): class CommandCompletionModel(base.BaseCompletionModel):
@ -176,9 +177,7 @@ class TabCompletionModel(base.BaseCompletionModel):
objreg.get("app").new_window.connect(self.on_new_window) objreg.get("app").new_window.connect(self.on_new_window)
self.rebuild() self.rebuild()
# slot argument should be mainwindow.MainWindow but can't import @pyqtSlot(mainwindow.MainWindow)
# that at module level because of import loops.
@pyqtSlot(object)
def on_new_window(self, window): def on_new_window(self, window):
"""Add hooks to new windows.""" """Add hooks to new windows."""
window.tabbed_browser.new_tab.connect(self.on_new_tab) window.tabbed_browser.new_tab.connect(self.on_new_tab)

View File

@ -95,6 +95,7 @@ class change_filter: # pylint: disable=invalid-name
""" """
if self._function: if self._function:
@pyqtSlot(str, str) @pyqtSlot(str, str)
@pyqtSlot()
@functools.wraps(func) @functools.wraps(func)
def wrapper(sectname=None, optname=None): def wrapper(sectname=None, optname=None):
if sectname is None and optname is None: if sectname is None and optname is None:
@ -108,6 +109,7 @@ class change_filter: # pylint: disable=invalid-name
return func() return func()
else: else:
@pyqtSlot(str, str) @pyqtSlot(str, str)
@pyqtSlot()
@functools.wraps(func) @functools.wraps(func)
def wrapper(wrapper_self, sectname=None, optname=None): def wrapper(wrapper_self, sectname=None, optname=None):
if sectname is None and optname is None: if sectname is None and optname is None:

View File

@ -22,6 +22,7 @@
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from qutebrowser.mainwindow.statusbar import textbase from qutebrowser.mainwindow.statusbar import textbase
from qutebrowser.browser import webview
class Percentage(textbase.TextBase): class Percentage(textbase.TextBase):
@ -48,7 +49,7 @@ class Percentage(textbase.TextBase):
else: else:
self.setText('[{:2}%]'.format(y)) self.setText('[{:2}%]'.format(y))
@pyqtSlot(object) @pyqtSlot(webview.WebView)
def on_tab_changed(self, tab): def on_tab_changed(self, tab):
"""Update scroll position when tab changed.""" """Update scroll position when tab changed."""
self.set_perc(*tab.scroll_pos) self.set_perc(*tab.scroll_pos)

View File

@ -59,7 +59,7 @@ class Progress(QProgressBar):
self.setValue(0) self.setValue(0)
self.show() self.show()
@pyqtSlot(int) @pyqtSlot(webview.WebView)
def on_tab_changed(self, tab): def on_tab_changed(self, tab):
"""Set the correct value when the current tab changed.""" """Set the correct value when the current tab changed."""
if self is None: # pragma: no branch if self is None: # pragma: no branch

View File

@ -24,6 +24,7 @@ from PyQt5.QtCore import pyqtSlot
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.mainwindow.statusbar import textbase from qutebrowser.mainwindow.statusbar import textbase
from qutebrowser.utils import usertypes, log, objreg from qutebrowser.utils import usertypes, log, objreg
from qutebrowser.browser import webview
class Text(textbase.TextBase): class Text(textbase.TextBase):
@ -98,7 +99,7 @@ class Text(textbase.TextBase):
"""Clear jstext when page loading started.""" """Clear jstext when page loading started."""
self._jstext = '' self._jstext = ''
@pyqtSlot(int) @pyqtSlot(webview.WebView)
def on_tab_changed(self, tab): def on_tab_changed(self, tab):
"""Set the correct jstext when the current tab changed.""" """Set the correct jstext when the current tab changed."""
self._jstext = tab.statusbar_message self._jstext = tab.statusbar_message

View File

@ -158,7 +158,7 @@ class UrlText(textbase.TextBase):
self._hover_url = None self._hover_url = None
self._update_url() self._update_url()
@pyqtSlot(int) @pyqtSlot(webview.WebView)
def on_tab_changed(self, tab): def on_tab_changed(self, tab):
"""Update URL if the tab changed.""" """Update URL if the tab changed."""
self._hover_url = None self._hover_url = None

View File

@ -221,7 +221,7 @@ class IPCServer(QObject):
# This means we only use setSocketOption on Windows... # This means we only use setSocketOption on Windows...
os.chmod(self._server.fullServerName(), 0o700) os.chmod(self._server.fullServerName(), 0o700)
@pyqtSlot(int) @pyqtSlot('QLocalSocket::LocalSocketError')
def on_error(self, err): def on_error(self, err):
"""Raise SocketError on fatal errors.""" """Raise SocketError on fatal errors."""
if self._socket is None: if self._socket is None: