mypy: check_untyped_defs for qutebrowser.completion

This commit is contained in:
Florian Bruhin 2019-10-15 20:33:07 +02:00
parent 576f9d8dcf
commit d38752aa82
4 changed files with 17 additions and 10 deletions

View File

@ -132,8 +132,8 @@ disallow_incomplete_defs = True
[mypy-qutebrowser.commands.*]
check_untyped_defs = True
# [mypy-qutebrowser.completion.*]
# check_untyped_defs = True
[mypy-qutebrowser.completion.*]
check_untyped_defs = True
[mypy-qutebrowser.javascript.*]
check_untyped_defs = True

View File

@ -19,6 +19,8 @@
"""A model that proxies access to one or more completion categories."""
import typing
from PyQt5.QtCore import Qt, QModelIndex, QAbstractItemModel
from qutebrowser.utils import log, qtutils
@ -41,7 +43,7 @@ class CompletionModel(QAbstractItemModel):
def __init__(self, *, column_widths=(30, 70, 0), parent=None):
super().__init__(parent)
self.column_widths = column_widths
self._categories = []
self._categories = [] # type: typing.Sequence[QAbstractItemModel]
def _cat_from_idx(self, index):
"""Return the category pointed to by the given index.

View File

@ -30,13 +30,18 @@ from qutebrowser.completion.models import util
from qutebrowser.utils import qtutils, log
_ItemType = typing.Union[typing.Tuple[str],
typing.Tuple[str, str],
typing.Tuple[str, str, str]]
class ListCategory(QSortFilterProxyModel):
"""Expose a list of items as a category for the CompletionModel."""
def __init__(self,
name: str,
items: typing.Sequence[str],
items: typing.Iterable[_ItemType],
sort: bool = True,
delete_func: util.DeleteFuncType = None,
parent: QWidget = None):

View File

@ -51,7 +51,7 @@ def helptopic(*, info):
def quickmark(*, info=None): # pylint: disable=unused-argument
"""A CompletionModel filled with all quickmarks."""
def delete(data: typing.Sequence[int]) -> None:
def delete(data: typing.Sequence[str]) -> None:
"""Delete a quickmark from the completion menu."""
name = data[0]
quickmark_manager = objreg.get('quickmark-manager')
@ -68,7 +68,7 @@ def quickmark(*, info=None): # pylint: disable=unused-argument
def bookmark(*, info=None): # pylint: disable=unused-argument
"""A CompletionModel filled with all bookmarks."""
def delete(data: typing.Sequence[int]) -> None:
def delete(data: typing.Sequence[str]) -> None:
"""Delete a bookmark from the completion menu."""
urlstr = data[0]
log.completion.debug('Deleting bookmark {}'.format(urlstr))
@ -88,10 +88,10 @@ def session(*, info=None): # pylint: disable=unused-argument
from qutebrowser.misc import sessions
model = completionmodel.CompletionModel()
try:
sessions = ((name,) for name
in sessions.session_manager.list_sessions()
if not name.startswith('_'))
model.add_category(listcategory.ListCategory("Sessions", sessions))
sess = ((name,) for name
in sessions.session_manager.list_sessions()
if not name.startswith('_'))
model.add_category(listcategory.ListCategory("Sessions", sess))
except OSError:
log.completion.exception("Failed to list sessions!")
return model