From 2bb44d8e37093ab150610dd23667faf28f52c028 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sun, 31 Mar 2024 11:51:48 -0400 Subject: [PATCH] use typing_extensions module for python < 3.11 --- dev-requirements.txt | 2 ++ relay/config.py | 8 +++++++- relay/database/config.py | 8 +++++++- relay/logger.py | 8 +++++++- relay/misc.py | 8 +++++++- relay/views/base.py | 8 +++++++- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 6285aa4..aa8a793 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,3 +2,5 @@ flake8 == 7.0.0 mypy == 1.9.0 pyinstaller == 6.3.0 watchdog == 4.0.0 + +typing_extensions >= 4.10.0; python_version < '3.11.0' diff --git a/relay/config.py b/relay/config.py index 74758aa..7e95c29 100644 --- a/relay/config.py +++ b/relay/config.py @@ -13,7 +13,13 @@ from platformdirs import user_config_dir from .misc import IS_DOCKER if typing.TYPE_CHECKING: - from typing import Any, Self + from typing import Any + + try: + from typing import Self + + except ImportError: + from typing_extensions import Self if platform.system() == 'Windows': diff --git a/relay/database/config.py b/relay/database/config.py index 306cf4e..3922f62 100644 --- a/relay/database/config.py +++ b/relay/database/config.py @@ -10,7 +10,13 @@ from ..misc import boolean if typing.TYPE_CHECKING: from bsql import Row from collections.abc import Callable, Sequence - from typing import Any, Self + from typing import Any + + try: + from typing import Self + + except ImportError: + from typing_extensions import Self THEMES = { diff --git a/relay/logger.py b/relay/logger.py index 9729eb2..916fa71 100644 --- a/relay/logger.py +++ b/relay/logger.py @@ -9,7 +9,13 @@ from pathlib import Path if typing.TYPE_CHECKING: from collections.abc import Callable - from typing import Any, Self + from typing import Any + + try: + from typing import Self + + except ImportError: + from typing_extensions import Self class LogLevel(IntEnum): diff --git a/relay/misc.py b/relay/misc.py index ae18b2d..82b1fd2 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -18,9 +18,15 @@ except ImportError: from importlib_resources import files as pkgfiles # type: ignore if typing.TYPE_CHECKING: - from typing import Any, Self + from typing import Any from .application import Application + try: + from typing import Self + + except ImportError: + from typing_extensions import Self + T = typing.TypeVar('T') ResponseType = typing.TypedDict('ResponseType', { diff --git a/relay/views/base.py b/relay/views/base.py index 7cf8311..93b3e3b 100644 --- a/relay/views/base.py +++ b/relay/views/base.py @@ -16,13 +16,19 @@ if typing.TYPE_CHECKING: from aiohttp.web import Request from collections.abc import Callable, Generator, Sequence, Mapping from bsql import Database - from typing import Any, Self + from typing import Any from ..application import Application from ..cache import Cache from ..config import Config from ..http_client import HttpClient from ..template import Template + try: + from typing import Self + + except ImportError: + from typing_extensions import Self + VIEWS: list[tuple[str, type[View]]] = []