summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-06-30 16:04:06 +0200
committerFlorian Bruhin <me@the-compiler.org>2023-06-30 16:05:02 +0200
commit0e242f7466b3b072108c931c508aacf816b90086 (patch)
tree1c2a09cc937d36a9c3ab7df7a2125046b4be982c
parent8dd5ba0abed58909b0705e245e83a2339348e2e7 (diff)
downloadqutebrowser-0e242f7466b3b072108c931c508aacf816b90086.tar.gz
qutebrowser-0e242f7466b3b072108c931c508aacf816b90086.zip
typing updates after Python 3.7 drop
-rw-r--r--qutebrowser/utils/log.py18
-rw-r--r--qutebrowser/utils/qtutils.py4
-rw-r--r--qutebrowser/utils/utils.py10
3 files changed, 13 insertions, 19 deletions
diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py
index f9d880612..521f52b5b 100644
--- a/qutebrowser/utils/log.py
+++ b/qutebrowser/utils/log.py
@@ -31,7 +31,7 @@ import json
import inspect
import argparse
from typing import (TYPE_CHECKING, Any, Iterator, Mapping, MutableSequence,
- Optional, Set, Tuple, Union, TextIO, cast)
+ Optional, Set, Tuple, Union, TextIO, Literal, cast)
from qutebrowser.qt import core as qtcore
# Optional imports
@@ -241,11 +241,13 @@ def disable_qt_msghandler() -> Iterator[None]:
@contextlib.contextmanager
-def py_warning_filter(action: str = 'ignore', **kwargs: Any) -> Iterator[None]:
+def py_warning_filter(
+ action:
+ Literal['default', 'error', 'ignore', 'always', 'module', 'once'] = 'ignore',
+ **kwargs: Any,
+) -> Iterator[None]:
"""Contextmanager to temporarily disable certain Python warnings."""
- # FIXME Use Literal['default', 'error', 'ignore', 'always', 'module', 'once']
- # once we use Python 3.8 or typing_extensions
- warnings.filterwarnings(action, **kwargs) # type: ignore[arg-type]
+ warnings.filterwarnings(action, **kwargs)
yield
if _log_inited:
_init_py_warnings()
@@ -726,10 +728,10 @@ class ColoredFormatter(logging.Formatter):
def __init__(self, fmt: str,
datefmt: str,
- style: str, *,
+ style: Literal["%", "{", "$"],
+ *,
use_colors: bool) -> None:
- # FIXME Use Literal["%", "{", "$"] once we use Python 3.8 or typing_extensions
- super().__init__(fmt, datefmt, style) # type: ignore[arg-type]
+ super().__init__(fmt, datefmt, style)
self.use_colors = use_colors
def format(self, record: logging.LogRecord) -> str:
diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py
index 340ae520b..cc34057ef 100644
--- a/qutebrowser/utils/qtutils.py
+++ b/qutebrowser/utils/qtutils.py
@@ -32,7 +32,7 @@ import pathlib
import operator
import contextlib
from typing import (Any, AnyStr, TYPE_CHECKING, BinaryIO, IO, Iterator,
- Optional, Union, Tuple, cast)
+ Optional, Union, Tuple, Protocol, cast)
from qutebrowser.qt import machinery, sip
from qutebrowser.qt.core import (qVersion, QEventLoop, QDataStream, QByteArray,
@@ -157,7 +157,7 @@ def check_overflow(arg: int, ctype: str, fatal: bool = True) -> int:
return arg
-class Validatable(utils.Protocol):
+class Validatable(Protocol):
"""An object with an isValid() method (e.g. QUrl)."""
diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py
index c78397372..a81952b7d 100644
--- a/qutebrowser/utils/utils.py
+++ b/qutebrowser/utils/utils.py
@@ -33,15 +33,7 @@ import shlex
import mimetypes
from typing import (Any, Callable, IO, Iterator,
Optional, Sequence, Tuple, List, Type, Union,
- TypeVar, TYPE_CHECKING)
-try:
- # Protocol was added in Python 3.8
- from typing import Protocol
-except ImportError: # pragma: no cover
- if not TYPE_CHECKING:
- class Protocol:
-
- """Empty stub at runtime."""
+ TypeVar, Protocol)
from qutebrowser.qt.core import QUrl, QVersionNumber, QRect, QPoint
from qutebrowser.qt.gui import QClipboard, QDesktopServices