summaryrefslogtreecommitdiff
path: root/qutebrowser/utils/utils.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-11-20 11:03:25 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-11-20 11:17:24 +0100
commit0e624e64695e8f566c7391f65f737311aeb6b2eb (patch)
treece852ca7c03f68c6a7918cf37120425d845514bd /qutebrowser/utils/utils.py
parent46e6839e21d9ff72abb6c5d49d5abaa5a8da8a81 (diff)
downloadqutebrowser-0e624e64695e8f566c7391f65f737311aeb6b2eb.tar.gz
qutebrowser-0e624e64695e8f566c7391f65f737311aeb6b2eb.zip
Work around QVersionNumber mypy stubs issue
See https://github.com/qutebrowser/qutebrowser/pull/5852#discussion_r515494417
Diffstat (limited to 'qutebrowser/utils/utils.py')
-rw-r--r--qutebrowser/utils/utils.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py
index 851de4250..4550453b5 100644
--- a/qutebrowser/utils/utils.py
+++ b/qutebrowser/utils/utils.py
@@ -36,7 +36,8 @@ import glob
import mimetypes
import ctypes
import ctypes.util
-from typing import Any, Callable, IO, Iterator, Optional, Sequence, Tuple, Type, Union
+from typing import (Any, Callable, IO, Iterator, Optional, Sequence, Tuple, Type, Union,
+ TYPE_CHECKING, cast)
from PyQt5.QtCore import QUrl, QVersionNumber
from PyQt5.QtGui import QColor, QClipboard, QDesktopServices
@@ -66,6 +67,22 @@ is_windows = sys.platform.startswith('win')
is_posix = os.name == 'posix'
+if TYPE_CHECKING:
+ # Protocol was added in Python 3.8
+ from typing import Protocol
+
+ class SupportsLessThan(Protocol):
+
+ """Protocol for the _T TypeVar below."""
+
+ def __lt__(self, other: Any) -> bool:
+ ...
+
+ class VersionNumber(SupportsLessThan, QVersionNumber):
+
+ """WORKAROUND for incorrect PyQt stubs."""
+
+
class Unreachable(Exception):
"""Raised when there was unreachable code."""
@@ -210,10 +227,10 @@ def resource_filename(filename: str) -> str:
return pkg_resources.resource_filename(qutebrowser.__name__, filename)
-def parse_version(version: str) -> QVersionNumber:
+def parse_version(version: str) -> 'VersionNumber':
"""Parse a version string."""
v_q, _suffix = QVersionNumber.fromString(version)
- return v_q.normalized()
+ return cast('VersionNumber', v_q.normalized())
def _get_color_percentage(x1: int, y1: int, z1: int, a1: int,