From 5217516c8a5c6b00711a4784eea4caf26801de4d Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Tue, 25 Jun 2024 16:54:04 -0400 Subject: [PATCH] move Self imports to typing block --- relay/config.py | 13 ++++++++----- relay/database/config.py | 11 ++++++----- relay/logger.py | 13 ++++++++----- relay/misc.py | 12 ++++++------ relay/views/base.py | 8 ++++---- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/relay/config.py b/relay/config.py index 7e86ef7..eccc1ab 100644 --- a/relay/config.py +++ b/relay/config.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import getpass import os import platform @@ -6,15 +8,16 @@ import yaml from dataclasses import asdict, dataclass, fields from pathlib import Path from platformdirs import user_config_dir -from typing import Any +from typing import TYPE_CHECKING, Any from .misc import IS_DOCKER -try: - from typing import Self +if TYPE_CHECKING: + try: + from typing import Self -except ImportError: - from typing_extensions 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 6effbb9..2be3ecc 100644 --- a/relay/database/config.py +++ b/relay/database/config.py @@ -5,16 +5,17 @@ from __future__ import annotations from bsql import Row from collections.abc import Callable, Sequence from dataclasses import Field, asdict, dataclass, fields -from typing import Any +from typing import TYPE_CHECKING, Any from .. import logger as logging from ..misc import boolean -try: - from typing import Self +if TYPE_CHECKING: + try: + from typing import Self -except ImportError: - from typing_extensions import Self + except ImportError: + from typing_extensions import Self THEMES = { diff --git a/relay/logger.py b/relay/logger.py index f1a1bd7..f4ef1f7 100644 --- a/relay/logger.py +++ b/relay/logger.py @@ -1,15 +1,18 @@ +from __future__ import annotations + import logging import os from enum import IntEnum from pathlib import Path -from typing import Any, Protocol +from typing import TYPE_CHECKING, Any, Protocol -try: - from typing import Self +if TYPE_CHECKING: + try: + from typing import Self -except ImportError: - from typing_extensions import Self + except ImportError: + from typing_extensions import Self class LoggingMethod(Protocol): diff --git a/relay/misc.py b/relay/misc.py index 9e8f035..37764e7 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -19,15 +19,15 @@ try: except ImportError: from importlib_resources import files as pkgfiles # type: ignore -try: - from typing import Self - -except ImportError: - from typing_extensions import Self - if TYPE_CHECKING: from .application import Application + try: + from typing import Self + + except ImportError: + from typing_extensions import Self + T = TypeVar('T') ResponseType = TypedDict('ResponseType', { diff --git a/relay/views/base.py b/relay/views/base.py index 350016c..64f792e 100644 --- a/relay/views/base.py +++ b/relay/views/base.py @@ -21,11 +21,11 @@ if TYPE_CHECKING: from ..application import Application from ..template import Template -try: - from typing import Self + try: + from typing import Self -except ImportError: - from typing_extensions import Self + except ImportError: + from typing_extensions import Self HandlerCallback = Callable[[Request], Awaitable[Response]]