summaryrefslogtreecommitdiff
path: root/qutebrowser/api
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/api
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/api')
-rw-r--r--qutebrowser/api/cmdutils.py19
-rw-r--r--qutebrowser/api/config.py6
-rw-r--r--qutebrowser/api/hook.py8
3 files changed, 16 insertions, 17 deletions
diff --git a/qutebrowser/api/cmdutils.py b/qutebrowser/api/cmdutils.py
index 5d74991c1..7f0be1afd 100644
--- a/qutebrowser/api/cmdutils.py
+++ b/qutebrowser/api/cmdutils.py
@@ -44,13 +44,13 @@ Possible values:
- A callable (``int``, ``float``, etc.): Gets called to validate/convert the
value.
- A python enum type: All members of the enum are possible values.
-- A ``typing.Union`` of multiple types above: Any of these types are valid
- values, e.g., ``typing.Union[str, int]``.
+- A ``Union`` of multiple types above: Any of these types are valid
+ values, e.g., ``Union[str, int]``.
"""
import inspect
-import typing
+from typing import Any, Callable, Iterable
from qutebrowser.utils import qtutils
from qutebrowser.commands import command, cmdexc
@@ -91,8 +91,7 @@ def check_overflow(arg: int, ctype: str) -> None:
"representation.".format(ctype))
-def check_exclusive(flags: typing.Iterable[bool],
- names: typing.Iterable[str]) -> None:
+def check_exclusive(flags: Iterable[bool], names: Iterable[str]) -> None:
"""Check if only one flag is set with exclusive flags.
Raise a CommandError if not.
@@ -113,7 +112,7 @@ class register: # noqa: N801,N806 pylint: disable=invalid-name
def __init__(self, *,
instance: str = None,
name: str = None,
- **kwargs: typing.Any) -> None:
+ **kwargs: Any) -> None:
"""Save decorator arguments.
Gets called on parse-time with the decorator arguments.
@@ -128,7 +127,7 @@ class register: # noqa: N801,N806 pylint: disable=invalid-name
# The arguments to pass to Command.
self._kwargs = kwargs
- def __call__(self, func: typing.Callable) -> typing.Callable:
+ def __call__(self, func: Callable) -> Callable:
"""Register the command before running the function.
Gets called when a function should be decorated.
@@ -175,7 +174,7 @@ class argument: # noqa: N801,N806 pylint: disable=invalid-name
def foo(bar: str):
...
- For ``typing.Union`` types, the given ``choices`` are only checked if other
+ For ``Union`` types, the given ``choices`` are only checked if other
types (like ``int``) don't match.
The following arguments are supported for ``@cmdutils.argument``:
@@ -197,11 +196,11 @@ class argument: # noqa: N801,N806 pylint: disable=invalid-name
trailing underscores stripped and underscores replaced by dashes.
"""
- def __init__(self, argname: str, **kwargs: typing.Any) -> None:
+ def __init__(self, argname: str, **kwargs: Any) -> None:
self._argname = argname # The name of the argument to handle.
self._kwargs = kwargs # Valid ArgInfo members.
- def __call__(self, func: typing.Callable) -> typing.Callable:
+ def __call__(self, func: Callable) -> Callable:
funcname = func.__name__
if self._argname not in inspect.signature(func).parameters:
diff --git a/qutebrowser/api/config.py b/qutebrowser/api/config.py
index 3b84a999c..fb363d858 100644
--- a/qutebrowser/api/config.py
+++ b/qutebrowser/api/config.py
@@ -19,7 +19,7 @@
"""Access to the qutebrowser configuration."""
-import typing
+from typing import cast, Any
from PyQt5.QtCore import QUrl
@@ -35,9 +35,9 @@ from qutebrowser.config import config
#: This also supports setting configuration values::
#:
#: config.val.content.javascript.enabled = False
-val = typing.cast('config.ConfigContainer', None)
+val = cast('config.ConfigContainer', None)
-def get(name: str, url: QUrl = None) -> typing.Any:
+def get(name: str, url: QUrl = None) -> Any:
"""Get a value from the config based on a string name."""
return config.instance.get(name, url)
diff --git a/qutebrowser/api/hook.py b/qutebrowser/api/hook.py
index 9bd14a8a1..4eadb2a99 100644
--- a/qutebrowser/api/hook.py
+++ b/qutebrowser/api/hook.py
@@ -22,13 +22,13 @@
"""Hooks for extensions."""
import importlib
-import typing
+from typing import Callable
from qutebrowser.extensions import loader
-def _add_module_info(func: typing.Callable) -> loader.ModuleInfo:
+def _add_module_info(func: Callable) -> loader.ModuleInfo:
"""Add module info to the given function."""
module = importlib.import_module(func.__module__)
return loader.add_module_info(module)
@@ -48,7 +48,7 @@ class init:
message.info("Extension initialized.")
"""
- def __call__(self, func: typing.Callable) -> typing.Callable:
+ def __call__(self, func: Callable) -> Callable:
info = _add_module_info(func)
if info.init_hook is not None:
raise ValueError("init hook is already registered!")
@@ -86,7 +86,7 @@ class config_changed:
def __init__(self, option_filter: str = None) -> None:
self._filter = option_filter
- def __call__(self, func: typing.Callable) -> typing.Callable:
+ def __call__(self, func: Callable) -> Callable:
info = _add_module_info(func)
info.config_changed_hooks.append((self._filter, func))
return func