diff options
author | Tim Brown <stimut@gmail.com> | 2020-10-28 09:30:48 +1000 |
---|---|---|
committer | Tim Brown <stimut@gmail.com> | 2020-10-28 09:30:48 +1000 |
commit | 08101e84488ec0ab4d2eae5dddbfc35328b7b0cb (patch) | |
tree | 5cfdf38aa7c83823ff79a132a327ee058586950b /qutebrowser/commands | |
parent | 37d7a195a9e47c8d6e3b603d90ad2130a7ce683e (diff) | |
download | qutebrowser-08101e84488ec0ab4d2eae5dddbfc35328b7b0cb.tar.gz qutebrowser-08101e84488ec0ab4d2eae5dddbfc35328b7b0cb.zip |
mypy: use from-import style
Update files in `api`, `commands`, `completion`, `components`, and
`etensions`.
See #5396
Diffstat (limited to 'qutebrowser/commands')
-rw-r--r-- | qutebrowser/commands/command.py | 15 | ||||
-rw-r--r-- | qutebrowser/commands/runners.py | 16 | ||||
-rw-r--r-- | qutebrowser/commands/userscripts.py | 10 |
3 files changed, 20 insertions, 21 deletions
diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 715bf4972..61b44d555 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -23,6 +23,7 @@ import inspect import collections import traceback import typing +from typing import Any, MutableMapping, MutableSequence, Tuple, Union import attr @@ -116,13 +117,11 @@ class Command: self.parser.add_argument('-h', '--help', action=argparser.HelpAction, default=argparser.SUPPRESS, nargs=0, help=argparser.SUPPRESS) - self.opt_args = collections.OrderedDict( - ) # type: typing.MutableMapping[str, typing.Tuple[str, str]] + self.opt_args: MutableMapping[str, Tuple[str, str]] = collections.OrderedDict() self.namespace = None self._count = None - self.pos_args = [ - ] # type: typing.MutableSequence[typing.Tuple[str, str]] - self.flags_with_args = [] # type: typing.MutableSequence[str] + self.pos_args: MutableSequence[Tuple[str, str]] = [] + self.flags_with_args: MutableSequence[str] = [] self._has_vararg = False # This is checked by future @cmdutils.argument calls so they fail @@ -412,7 +411,7 @@ class Command: # typing.get_origin was added in Python 3.8 origin = getattr(typ, '__origin__', None) - if origin is typing.Union: + if origin is Union: try: types = list(typing.get_args(typ)) # type: ignore[attr-defined] except AttributeError: @@ -494,8 +493,8 @@ class Command: Return: An (args, kwargs) tuple. """ - args = [] # type: typing.Any - kwargs = {} # type: typing.MutableMapping[str, typing.Any] + args: Any = [] + kwargs: MutableMapping[str, Any] = {} signature = inspect.signature(self.handler) for i, param in enumerate(signature.parameters.values()): diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 76ae1d64f..c195a8be9 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -21,8 +21,8 @@ import traceback import re -import typing import contextlib +from typing import TYPE_CHECKING, Callable, Dict, Iterator, Mapping, MutableMapping import attr from PyQt5.QtCore import pyqtSlot, QUrl, QObject @@ -34,9 +34,9 @@ from qutebrowser.utils import message, objreg, qtutils, usertypes, utils from qutebrowser.misc import split, objects from qutebrowser.keyinput import macros, modeman -if typing.TYPE_CHECKING: +if TYPE_CHECKING: from qutebrowser.mainwindow import tabbedbrowser -_ReplacementFunction = typing.Callable[['tabbedbrowser.TabbedBrowser'], str] +_ReplacementFunction = Callable[['tabbedbrowser.TabbedBrowser'], str] last_command = {} @@ -64,9 +64,9 @@ def _url(tabbed_browser): raise cmdutils.CommandError(msg) -def _init_variable_replacements() -> typing.Mapping[str, _ReplacementFunction]: +def _init_variable_replacements() -> Mapping[str, _ReplacementFunction]: """Return a dict from variable replacements to fns processing them.""" - replacements = { + replacements: Dict[str, _ReplacementFunction] = { 'url': lambda tb: _url(tb).toString( QUrl.FullyEncoded | QUrl.RemovePassword), 'url:pretty': lambda tb: _url(tb).toString( @@ -88,7 +88,7 @@ def _init_variable_replacements() -> typing.Mapping[str, _ReplacementFunction]: 'title': lambda tb: tb.widget.page_title(tb.widget.currentIndex()), 'clipboard': lambda _: utils.get_clipboard(), 'primary': lambda _: utils.get_clipboard(selection=True), - } # type: typing.Dict[str, _ReplacementFunction] + } for key in list(replacements): modified_key = '{' + key + '}' @@ -108,7 +108,7 @@ def replace_variables(win_id, arglist): """Utility function to replace variables like {url} in a list of args.""" tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) - values = {} # type: typing.MutableMapping[str, str] + values: MutableMapping[str, str] = {} args = [] def repl_cb(matchobj): @@ -332,7 +332,7 @@ class CommandRunner(AbstractCommandRunner): self._win_id = win_id @contextlib.contextmanager - def _handle_error(self, safely: bool) -> typing.Iterator[None]: + def _handle_error(self, safely: bool) -> Iterator[None]: """Show exceptions as errors if safely=True is given.""" try: yield diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index ba4cdfd93..ce25d7d28 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -22,7 +22,7 @@ import os import os.path import tempfile -import typing +from typing import cast, Any, MutableMapping, Tuple from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QSocketNotifier @@ -60,7 +60,7 @@ class _QtFIFOReader(QObject): fd = os.open(filepath, os.O_RDWR | os.O_NONBLOCK) # pylint: enable=no-member,useless-suppression self._fifo = os.fdopen(fd, 'r') - self._notifier = QSocketNotifier(typing.cast(sip.voidptr, fd), + self._notifier = QSocketNotifier(cast(sip.voidptr, fd), QSocketNotifier.Read, self) self._notifier.activated.connect( # type: ignore[attr-defined] self.read_line) @@ -117,10 +117,10 @@ class _BaseUserscriptRunner(QObject): self._cleaned_up = False self._filepath = None self._proc = None - self._env = {} # type: typing.MutableMapping[str, str] + self._env: MutableMapping[str, str] = {} self._text_stored = False self._html_stored = False - self._args = () # type: typing.Tuple[typing.Any, ...] + self._args: Tuple[Any, ...] = () self._kwargs = {} def store_text(self, text): @@ -426,7 +426,7 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False, commandrunner = runners.CommandRunner(win_id, parent=tb) if utils.is_posix: - runner = _POSIXUserscriptRunner(tb) # type: _BaseUserscriptRunner + runner: _BaseUserscriptRunner = _POSIXUserscriptRunner(tb) elif utils.is_windows: # pragma: no cover runner = _WindowsUserscriptRunner(tb) else: # pragma: no cover |