mypy: Fix inspector typing

The previous solution with making AbstractInspector know about the concrete
inspector types results in Liskov issues for the backend-specific overrides:
https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides

So, for now, let's just declare them as Any. Perhaps we should have a
typing.Protocol to unify the two, as they don't share a common base class.
See #7098.
This commit is contained in:
Florian Bruhin 2022-04-25 11:44:33 +02:00
parent a20bb67a87
commit 737fafd313
2 changed files with 5 additions and 10 deletions

View File

@ -22,7 +22,7 @@
import base64
import binascii
import enum
from typing import cast, Optional, Union, TYPE_CHECKING
from typing import cast, Optional, Any, TYPE_CHECKING
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QEvent
@ -34,13 +34,9 @@ from qutebrowser.utils import log, usertypes
from qutebrowser.keyinput import modeman
from qutebrowser.misc import miscwidgets
if TYPE_CHECKING:
from PyQt5.QtWebKitWidgets import QWebInspector, QWebPage
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from qutebrowser.browser.webengine import webengineinspector
_WidgetType = Union["QWebInspector", "webengineinspector.WebEngineInspectorView"]
# FIXME:mypy How to annotate this properly without running into Liskov issues?
_WidgetType = Any
class Position(enum.Enum):
@ -206,7 +202,8 @@ class AbstractWebInspector(QWidget):
geom = base64.b64encode(data).decode('ASCII')
configfiles.state['inspector']['window'] = geom
def inspect(self, page: Union["QWebPage", "QWebEnginePage"]) -> None:
# FIXME:mypy How to annotate 'page' properly without running into Liskov issues?
def inspect(self, page: Any) -> None:
"""Inspect the given QWeb(Engine)Page."""
raise NotImplementedError

View File

@ -31,8 +31,6 @@ class WebKitInspector(inspector.AbstractWebInspector):
"""A web inspector for QtWebKit."""
_widget = QWebInspector
def __init__(self, splitter: miscwidgets.InspectorSplitter,
win_id: int,
parent: QWidget = None) -> None: