Adding TypeAlias for ruff issues
TypeAlias import and his use added in every file we have a ruff issue.
This commit is contained in:
parent
9316d428ef
commit
99e9a026bd
|
|
@ -9,7 +9,7 @@ import pathlib
|
|||
import itertools
|
||||
import functools
|
||||
import dataclasses
|
||||
from typing import (cast, TYPE_CHECKING, Any, Optional, Union)
|
||||
from typing import (cast, TYPE_CHECKING, Any, Optional, Union, TypeAlias)
|
||||
from collections.abc import Iterable, Sequence, Callable
|
||||
|
||||
from qutebrowser.qt import machinery
|
||||
|
|
@ -42,7 +42,7 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
tab_id_gen = itertools.count(0)
|
||||
_WidgetType = Union["WebView", "WebEngineView"]
|
||||
_WidgetType: TypeAlias = Union["WebView", "WebEngineView"]
|
||||
|
||||
|
||||
def create(win_id: int,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
"""Generic web element related code."""
|
||||
|
||||
from typing import Optional, TYPE_CHECKING, Union
|
||||
from typing import Optional, TYPE_CHECKING, Union, TypeAlias
|
||||
from collections.abc import Iterator
|
||||
import collections.abc
|
||||
|
||||
|
|
@ -20,12 +20,12 @@ if TYPE_CHECKING:
|
|||
from qutebrowser.browser import browsertab
|
||||
|
||||
|
||||
JsValueType = Union[int, float, str, None]
|
||||
JsValueType: TypeAlias = Union[int, float, str, None]
|
||||
|
||||
if machinery.IS_QT6:
|
||||
KeyboardModifierType = Qt.KeyboardModifier
|
||||
else:
|
||||
KeyboardModifierType = Union[Qt.KeyboardModifiers, Qt.KeyboardModifier]
|
||||
KeyboardModifierType: TypeAlias = Union[Qt.KeyboardModifiers, Qt.KeyboardModifier]
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ import copy
|
|||
import enum
|
||||
import dataclasses
|
||||
import collections
|
||||
from typing import (Any, Optional, Union)
|
||||
from typing import (Any, Optional, Union, TypeAlias)
|
||||
from collections.abc import Iterator, Mapping, MutableMapping, Sequence
|
||||
|
||||
from qutebrowser.config import config
|
||||
|
|
@ -340,7 +340,7 @@ _DEFINITIONS[Variant.qt_66] = _DEFINITIONS[Variant.qt_64].copy_add_setting(
|
|||
_DEFINITIONS[Variant.qt_67] = _DEFINITIONS[Variant.qt_66].copy_remove_setting('enabled')
|
||||
|
||||
|
||||
_SettingValType = Union[str, usertypes.Unset]
|
||||
_SettingValType: TypeAlias = Union[str, usertypes.Unset]
|
||||
_PREFERRED_COLOR_SCHEME_DEFINITIONS: MutableMapping[Variant, Mapping[_SettingValType, str]] = {
|
||||
Variant.qt_515_2: {
|
||||
# 0: no-preference (not exposed)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import functools
|
|||
import dataclasses
|
||||
import re
|
||||
import html as html_utils
|
||||
from typing import cast, Union, Optional
|
||||
from typing import cast, Union, Optional, TypeAlias
|
||||
|
||||
from qutebrowser.qt.core import (pyqtSignal, pyqtSlot, Qt, QPoint, QPointF, QUrl,
|
||||
QObject, QByteArray, QTimer)
|
||||
|
|
@ -92,7 +92,7 @@ class WebEnginePrinting(browsertab.AbstractPrinting):
|
|||
|
||||
|
||||
if machinery.IS_QT5:
|
||||
_FindFlagType = Union[QWebEnginePage.FindFlag, QWebEnginePage.FindFlags]
|
||||
_FindFlagType: TypeAlias = Union[QWebEnginePage.FindFlag, QWebEnginePage.FindFlags]
|
||||
else:
|
||||
_FindFlagType = QWebEnginePage.FindFlag
|
||||
|
||||
|
|
@ -1379,7 +1379,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||
log.misc.debug("run_js_async called on deleted tab")
|
||||
return
|
||||
|
||||
world_id_type = Union[QWebEngineScript.ScriptWorldId, int]
|
||||
world_id_type: TypeAlias = Union[QWebEngineScript.ScriptWorldId, int]
|
||||
if world is None:
|
||||
world_id: world_id_type = QWebEngineScript.ScriptWorldId.ApplicationWorld
|
||||
elif isinstance(world, int):
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import functools
|
|||
import operator
|
||||
import json
|
||||
import dataclasses
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any, Optional, Union, TypeAlias
|
||||
from re import Pattern
|
||||
from collections.abc import Iterable, Iterator, Sequence, Callable
|
||||
|
||||
|
|
@ -67,9 +67,9 @@ BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
|
|||
|
||||
|
||||
_Completions = Optional[Iterable[tuple[str, str]]]
|
||||
_StrUnset = Union[str, usertypes.Unset]
|
||||
_UnsetNone = Union[None, usertypes.Unset]
|
||||
_StrUnsetNone = Union[str, _UnsetNone]
|
||||
_StrUnset: TypeAlias = Union[str, usertypes.Unset]
|
||||
_UnsetNone: TypeAlias = Union[None, usertypes.Unset]
|
||||
_StrUnsetNone: TypeAlias = Union[str, _UnsetNone]
|
||||
|
||||
|
||||
def _validate_encoding(encoding: Optional[str], value: str) -> None:
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import pathlib
|
|||
# Using deprecated typing.Callable as a WORKAROUND because
|
||||
# collections.abc.Callable inside Optional[...]/Union[...]
|
||||
# is broken on Python 3.9.0 and 3.9.1
|
||||
from typing import Any, Optional, Union, Callable
|
||||
from typing import Any, Optional, Union, Callable, TypeAlias
|
||||
from collections.abc import Iterator, Sequence
|
||||
|
||||
from qutebrowser.qt import machinery
|
||||
|
|
@ -291,7 +291,7 @@ def _qtwebengine_args(
|
|||
yield from _qtwebengine_settings_args(versions)
|
||||
|
||||
|
||||
_SettingValueType = Union[
|
||||
_SettingValueType: TypeAlias = Union[
|
||||
str,
|
||||
Callable[
|
||||
[
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ handle what we actually think we do.
|
|||
|
||||
import itertools
|
||||
import dataclasses
|
||||
from typing import Optional, Union, overload, cast
|
||||
from typing import Optional, Union, overload, cast, TypeAlias
|
||||
from collections.abc import Iterator, Iterable, Mapping
|
||||
|
||||
from qutebrowser.qt import machinery
|
||||
|
|
@ -63,7 +63,7 @@ if machinery.IS_QT6:
|
|||
_ModifierType = Qt.KeyboardModifier
|
||||
else:
|
||||
_KeyInfoType = int
|
||||
_ModifierType = Union[Qt.KeyboardModifiers, Qt.KeyboardModifier]
|
||||
_ModifierType: TypeAlias = Union[Qt.KeyboardModifiers, Qt.KeyboardModifier]
|
||||
|
||||
|
||||
_SPECIAL_NAMES = {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import itertools
|
|||
import urllib
|
||||
import shutil
|
||||
import pathlib
|
||||
from typing import Any, Optional, Union, cast
|
||||
from typing import Any, Optional, Union, cast, TypeAlias
|
||||
from collections.abc import Iterable, MutableMapping, MutableSequence
|
||||
|
||||
from qutebrowser.qt.core import Qt, QUrl, QObject, QPoint, QTimer, QDateTime
|
||||
|
|
@ -37,7 +37,7 @@ class Sentinel:
|
|||
default = Sentinel()
|
||||
session_manager = cast('SessionManager', None)
|
||||
|
||||
ArgType = Union[str, Sentinel]
|
||||
ArgType: TypeAlias = Union[str, Sentinel]
|
||||
|
||||
|
||||
def init(parent=None):
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import functools
|
|||
import datetime
|
||||
import types
|
||||
from typing import (
|
||||
Any, Optional, Union)
|
||||
Any, Optional, Union, TypeAlias)
|
||||
from collections.abc import Mapping, MutableSequence, Sequence, Callable
|
||||
|
||||
from qutebrowser.qt.core import Qt, QEvent, QMetaMethod, QObject, pyqtBoundSignal
|
||||
|
|
@ -89,9 +89,9 @@ def log_signals(obj: Union[QObject, type[QObject]]) -> Union[QObject, type[QObje
|
|||
|
||||
|
||||
if machinery.IS_QT6:
|
||||
_EnumValueType = Union[enum.Enum, int]
|
||||
_EnumValueType: TypeAlias = Union[enum.Enum, int]
|
||||
else:
|
||||
_EnumValueType = Union[sip.simplewrapper, int]
|
||||
_EnumValueType: TypeAlias = Union[sip.simplewrapper, int]
|
||||
|
||||
|
||||
def _qenum_key_python(
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
"""Utilities related to javascript interaction."""
|
||||
|
||||
from typing import Union
|
||||
from typing import Union, TypeAlias
|
||||
from collections.abc import Sequence
|
||||
|
||||
_InnerJsArgType = Union[None, str, bool, int, float]
|
||||
_JsArgType = Union[_InnerJsArgType, Sequence[_InnerJsArgType]]
|
||||
_InnerJsArgType: TypeAlias = Union[None, str, bool, int, float]
|
||||
_JsArgType: TypeAlias = Union[_InnerJsArgType, Sequence[_InnerJsArgType]]
|
||||
|
||||
|
||||
def string_escape(text: str) -> str:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
import collections
|
||||
import functools
|
||||
from typing import (TYPE_CHECKING, Any,
|
||||
Optional, Union)
|
||||
Optional, Union, TypeAlias)
|
||||
from collections.abc import MutableMapping, MutableSequence, Sequence, Callable
|
||||
|
||||
from qutebrowser.qt.core import QObject, QTimer
|
||||
|
|
@ -20,7 +20,7 @@ if TYPE_CHECKING:
|
|||
from qutebrowser.mainwindow import mainwindow
|
||||
|
||||
|
||||
_WindowTab = Union[str, int, None]
|
||||
_WindowTab: TypeAlias = Union[str, int, None]
|
||||
|
||||
|
||||
class RegistryUnavailableError(Exception):
|
||||
|
|
@ -38,7 +38,7 @@ class CommandOnlyError(Exception):
|
|||
"""Raised when an object is requested which is used for commands only."""
|
||||
|
||||
|
||||
_IndexType = Union[str, int]
|
||||
_IndexType: TypeAlias = Union[str, int]
|
||||
|
||||
|
||||
# UserDict is only generic in Python 3.9+
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import pathlib
|
|||
import operator
|
||||
import contextlib
|
||||
from typing import (Any, TYPE_CHECKING, BinaryIO, IO, Literal,
|
||||
Optional, Union, Protocol, cast, overload, TypeVar)
|
||||
Optional, Union, Protocol, cast, overload, TypeVar, TypeAlias)
|
||||
from collections.abc import Iterator
|
||||
|
||||
from qutebrowser.qt import machinery, sip
|
||||
|
|
@ -207,7 +207,7 @@ def check_qdatastream(stream: QDataStream) -> None:
|
|||
raise OSError(status_to_str[stream.status()])
|
||||
|
||||
|
||||
_QtSerializableType = Union[
|
||||
_QtSerializableType: TypeAlias = Union[
|
||||
QObject,
|
||||
QByteArray,
|
||||
QUrl,
|
||||
|
|
@ -499,7 +499,7 @@ class QtValueError(ValueError):
|
|||
if machinery.IS_QT6:
|
||||
_ProcessEventFlagType = QEventLoop.ProcessEventsFlag
|
||||
else:
|
||||
_ProcessEventFlagType = Union[
|
||||
_ProcessEventFlagType: TypeAlias = Union[
|
||||
QEventLoop.ProcessEventsFlag, QEventLoop.ProcessEventsFlags]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import contextlib
|
|||
import posixpath
|
||||
import pathlib
|
||||
import importlib.resources
|
||||
from typing import Union
|
||||
from typing import Union, TypeAlias
|
||||
from collections.abc import Iterator, Iterable
|
||||
|
||||
if sys.version_info >= (3, 11): # pragma: no cover
|
||||
|
|
@ -24,7 +24,7 @@ _cache: dict[str, str] = {}
|
|||
_bin_cache: dict[str, bytes] = {}
|
||||
|
||||
|
||||
_ResourceType = Union[Traversable, pathlib.Path]
|
||||
_ResourceType: TypeAlias = Union[Traversable, pathlib.Path]
|
||||
|
||||
|
||||
def _path(filename: str) -> _ResourceType:
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import ipaddress
|
|||
import posixpath
|
||||
import urllib.parse
|
||||
import mimetypes
|
||||
from typing import Optional, Union, cast
|
||||
from typing import Optional, Union, cast, TypeAlias
|
||||
from collections.abc import Iterable
|
||||
|
||||
from qutebrowser.qt import machinery
|
||||
|
|
@ -29,7 +29,7 @@ from qutebrowser.browser.network import pac
|
|||
|
||||
|
||||
if machinery.IS_QT6:
|
||||
UrlFlagsType = Union[QUrl.UrlFormattingOption, QUrl.ComponentFormattingOption]
|
||||
UrlFlagsType: TypeAlias = Union[QUrl.UrlFormattingOption, QUrl.ComponentFormattingOption]
|
||||
|
||||
class FormatOption:
|
||||
"""Simple wrapper around Qt enums to fix typing problems on Qt 5."""
|
||||
|
|
@ -42,7 +42,7 @@ if machinery.IS_QT6:
|
|||
REMOVE_PASSWORD = QUrl.UrlFormattingOption.RemovePassword
|
||||
REMOVE_QUERY = QUrl.UrlFormattingOption.RemoveQuery
|
||||
else:
|
||||
UrlFlagsType = Union[
|
||||
UrlFlagsType: TypeAlias = Union[
|
||||
QUrl.FormattingOptions,
|
||||
QUrl.UrlFormattingOption,
|
||||
QUrl.ComponentFormattingOption,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import sysconfig
|
|||
import mimetypes
|
||||
from typing import (Any, IO,
|
||||
Optional, Union,
|
||||
TypeVar, Protocol)
|
||||
TypeVar, Protocol, TypeAlias)
|
||||
from collections.abc import Iterator, Sequence, Callable
|
||||
|
||||
from qutebrowser.qt.core import QUrl, QVersionNumber, QRect, QPoint
|
||||
|
|
@ -408,7 +408,7 @@ def qualname(obj: Any) -> str:
|
|||
return repr(obj)
|
||||
|
||||
|
||||
_ExceptionType = Union[type[BaseException], tuple[type[BaseException]]]
|
||||
_ExceptionType: TypeAlias = Union[type[BaseException], tuple[type[BaseException]]]
|
||||
|
||||
|
||||
def raises(exc: _ExceptionType, func: Callable[..., Any], *args: Any) -> bool:
|
||||
|
|
|
|||
Loading…
Reference in New Issue