summaryrefslogtreecommitdiff
path: root/qutebrowser/extensions
diff options
context:
space:
mode:
authorTim Brown <stimut@gmail.com>2020-10-28 09:30:48 +1000
committerTim Brown <stimut@gmail.com>2020-10-28 09:30:48 +1000
commit08101e84488ec0ab4d2eae5dddbfc35328b7b0cb (patch)
tree5cfdf38aa7c83823ff79a132a327ee058586950b /qutebrowser/extensions
parent37d7a195a9e47c8d6e3b603d90ad2130a7ce683e (diff)
downloadqutebrowser-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/extensions')
-rw-r--r--qutebrowser/extensions/interceptors.py14
-rw-r--r--qutebrowser/extensions/loader.py30
2 files changed, 21 insertions, 23 deletions
diff --git a/qutebrowser/extensions/interceptors.py b/qutebrowser/extensions/interceptors.py
index 6c5756016..fddeaabc9 100644
--- a/qutebrowser/extensions/interceptors.py
+++ b/qutebrowser/extensions/interceptors.py
@@ -19,8 +19,8 @@
"""Infrastructure for intercepting requests."""
-import typing
import enum
+from typing import Callable, List, Optional
import attr
@@ -76,15 +76,15 @@ class Request:
"""A request which can be intercepted/blocked."""
#: The URL of the page being shown.
- first_party_url = attr.ib() # type: typing.Optional[QUrl]
+ first_party_url: Optional[QUrl] = attr.ib()
#: The URL of the file being requested.
- request_url = attr.ib() # type: QUrl
+ request_url: QUrl = attr.ib()
- is_blocked = attr.ib(False) # type: bool
+ is_blocked: bool = attr.ib(False)
#: The resource type of the request. None if not supported on this backend.
- resource_type = attr.ib(None) # type: typing.Optional[ResourceType]
+ resource_type: Optional[ResourceType] = attr.ib(None)
def block(self) -> None:
"""Block this request."""
@@ -107,10 +107,10 @@ class Request:
#: Type annotation for an interceptor function.
-InterceptorType = typing.Callable[[Request], None]
+InterceptorType = Callable[[Request], None]
-_interceptors = [] # type: typing.List[InterceptorType]
+_interceptors: List[InterceptorType] = []
def register(interceptor: InterceptorType) -> None:
diff --git a/qutebrowser/extensions/loader.py b/qutebrowser/extensions/loader.py
index f4649401f..bbaa81be9 100644
--- a/qutebrowser/extensions/loader.py
+++ b/qutebrowser/extensions/loader.py
@@ -21,10 +21,10 @@
import pkgutil
import types
-import typing
import sys
import pathlib
import importlib
+from typing import TYPE_CHECKING, Callable, Iterator, List, Optional, Set, Tuple
import attr
@@ -35,7 +35,7 @@ from qutebrowser.config import config
from qutebrowser.utils import log, standarddir
from qutebrowser.misc import objects
-if typing.TYPE_CHECKING:
+if TYPE_CHECKING:
import argparse
@@ -48,9 +48,9 @@ class InitContext:
"""Context an extension gets in its init hook."""
- data_dir = attr.ib() # type: pathlib.Path
- config_dir = attr.ib() # type: pathlib.Path
- args = attr.ib() # type: argparse.Namespace
+ data_dir: pathlib.Path = attr.ib()
+ config_dir: pathlib.Path = attr.ib()
+ args: 'argparse.Namespace' = attr.ib()
@attr.s
@@ -61,13 +61,11 @@ class ModuleInfo:
This gets used by qutebrowser.api.hook.
"""
- _ConfigChangedHooksType = typing.List[typing.Tuple[typing.Optional[str],
- typing.Callable]]
+ _ConfigChangedHooksType = List[Tuple[Optional[str], Callable]]
- skip_hooks = attr.ib(False) # type: bool
- init_hook = attr.ib(None) # type: typing.Optional[typing.Callable]
- config_changed_hooks = attr.ib(
- attr.Factory(list)) # type: _ConfigChangedHooksType
+ skip_hooks: bool = attr.ib(False)
+ init_hook: Optional[Callable] = attr.ib(None)
+ config_changed_hooks: _ConfigChangedHooksType = attr.ib(attr.Factory(list))
@attr.s
@@ -75,7 +73,7 @@ class ExtensionInfo:
"""Information about a qutebrowser extension."""
- name = attr.ib() # type: str
+ name: str = attr.ib()
def add_module_info(module: types.ModuleType) -> ModuleInfo:
@@ -92,7 +90,7 @@ def load_components(*, skip_hooks: bool = False) -> None:
_load_component(info, skip_hooks=skip_hooks)
-def walk_components() -> typing.Iterator[ExtensionInfo]:
+def walk_components() -> Iterator[ExtensionInfo]:
"""Yield ExtensionInfo objects for all modules."""
if hasattr(sys, 'frozen'):
yield from _walk_pyinstaller()
@@ -104,7 +102,7 @@ def _on_walk_error(name: str) -> None:
raise ImportError("Failed to import {}".format(name))
-def _walk_normal() -> typing.Iterator[ExtensionInfo]:
+def _walk_normal() -> Iterator[ExtensionInfo]:
"""Walk extensions when not using PyInstaller."""
for _finder, name, ispkg in pkgutil.walk_packages(
# Only packages have a __path__ attribute,
@@ -117,7 +115,7 @@ def _walk_normal() -> typing.Iterator[ExtensionInfo]:
yield ExtensionInfo(name=name)
-def _walk_pyinstaller() -> typing.Iterator[ExtensionInfo]:
+def _walk_pyinstaller() -> Iterator[ExtensionInfo]:
"""Walk extensions when using PyInstaller.
See https://github.com/pyinstaller/pyinstaller/issues/1905
@@ -125,7 +123,7 @@ def _walk_pyinstaller() -> typing.Iterator[ExtensionInfo]:
Inspired by:
https://github.com/webcomics/dosage/blob/master/dosagelib/loader.py
"""
- toc = set() # type: typing.Set[str]
+ toc: Set[str] = set()
for importer in pkgutil.iter_importers('qutebrowser'):
if hasattr(importer, 'toc'):
toc |= importer.toc