diff --git a/constants.py b/constants.py index 9d688de..f96d947 100644 --- a/constants.py +++ b/constants.py @@ -2,19 +2,21 @@ from __future__ import annotations import logging from copy import copy -from collections import abc from enum import Enum, auto from datetime import timedelta -from typing import Any, Literal +from typing import Any, Dict, Literal, TYPE_CHECKING from typing_extensions import TypeAlias from version import __version__ +if TYPE_CHECKING: + from collections import abc # noqa + # Typing -JsonType: TypeAlias = "dict[str, Any]" -TopicProcess = abc.Callable[[int, JsonType], Any] +JsonType = Dict[str, Any] +TopicProcess: TypeAlias = "abc.Callable[[int, JsonType], Any]" # Values MAX_WEBSOCKETS = 8 WS_TOPICS_LIMIT = 50 diff --git a/inventory.py b/inventory.py index 1dd81c4..4055a25 100644 --- a/inventory.py +++ b/inventory.py @@ -4,12 +4,12 @@ from typing import TYPE_CHECKING from functools import cached_property from datetime import datetime, timezone +from channel import Channel from constants import GQL_OPERATIONS from utils import timestamp, invalidate_cache, Game if TYPE_CHECKING: from twitch import Twitch - from channel import Channel from collections import abc from constants import JsonType from gui import CampaignProgress diff --git a/twitch.py b/twitch.py index 3952e05..e53aa2e 100644 --- a/twitch.py +++ b/twitch.py @@ -7,8 +7,8 @@ from yarl import URL from time import time from itertools import chain from functools import partial -from typing import TYPE_CHECKING from collections import OrderedDict +from typing import cast, TYPE_CHECKING from contextlib import suppress, asynccontextmanager try: @@ -38,9 +38,9 @@ from constants import ( ) if TYPE_CHECKING: + from typing import Final from collections import abc from datetime import datetime - from typing import Final, cast from utils import Game from gui import LoginForm diff --git a/utils.py b/utils.py index abdb097..39802b0 100644 --- a/utils.py +++ b/utils.py @@ -8,7 +8,7 @@ from functools import wraps from contextlib import suppress from datetime import datetime, timezone from collections import abc, OrderedDict -from typing import Any, Literal, Generic, TypeVar, cast, TYPE_CHECKING +from typing import Any, Literal, MutableSet, Generic, TypeVar, cast, TYPE_CHECKING from constants import JsonType @@ -62,7 +62,7 @@ def invalidate_cache(instance, *attrnames): delattr(instance, name) -class OrderedSet(abc.MutableSet[_T]): +class OrderedSet(MutableSet[_T]): """ Implementation of a set that preserves insertion order, based on OrderedDict with values set to None. @@ -111,7 +111,7 @@ class AwaitableValue(Generic[_T]): return self._event.is_set() def wait(self) -> abc.Coroutine[Any, Any, Literal[True]]: - return cast(abc.Coroutine[Any, Any, Literal[True]], self._event.wait()) + return cast("abc.Coroutine[Any, Any, Literal[True]]", self._event.wait()) def get_with_default(self, default: _D) -> _T | _D: if self._event.is_set():