diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 366223f34..f078418bc 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -30,7 +30,7 @@ from PyQt5.QtCore import QUrl from qutebrowser.utils import log, qtutils, utils -_T = TypeVar('_T', bound=utils.SupportsLessThan) +_T = TypeVar('_T', bound=utils.Comparable) class Unset: diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 73a36dd1b..945eb4ec4 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -37,7 +37,7 @@ import pathlib import ctypes import ctypes.util from typing import (Any, Callable, IO, Iterator, Optional, Sequence, Tuple, Type, Union, - Iterable, TYPE_CHECKING, cast) + Iterable, TypeVar, TYPE_CHECKING, cast) try: # Protocol was added in Python 3.8 from typing import Protocol @@ -78,17 +78,22 @@ is_linux = sys.platform.startswith('linux') is_windows = sys.platform.startswith('win') is_posix = os.name == 'posix' +_C = TypeVar("_C", bound="Comparable") -class SupportsLessThan(Protocol): + +class Comparable(Protocol): """Protocol for a "comparable" object.""" - def __lt__(self, other: Any) -> bool: + def __lt__(self: _C, other: _C) -> bool: + ... + + def __ge__(self: _C, other: _C) -> bool: ... if TYPE_CHECKING: - class VersionNumber(SupportsLessThan, QVersionNumber): + class VersionNumber(Comparable, QVersionNumber): """WORKAROUND for incorrect PyQt stubs.""" else: