From 0b6736b64abd9c6b8b97f973a3109006596b6bbb Mon Sep 17 00:00:00 2001 From: Ljzd-PRO <63289359+Ljzd-PRO@users.noreply.github.com> Date: Wed, 22 May 2024 02:58:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=BE=A9=20py3.9=20=E5=B0=8E?= =?UTF-8?q?=E5=85=A5=20Self=20=E5=A4=B1=E6=95=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_dg_lab_play/client_manager.py | 9 ++++++--- nonebot_plugin_dg_lab_play/config.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/nonebot_plugin_dg_lab_play/client_manager.py b/nonebot_plugin_dg_lab_play/client_manager.py index 8d521c2..2bc1150 100644 --- a/nonebot_plugin_dg_lab_play/client_manager.py +++ b/nonebot_plugin_dg_lab_play/client_manager.py @@ -1,6 +1,9 @@ import asyncio from functools import cached_property -from typing import Dict, Optional, Union, Self, Callable, Any, List, Tuple +from typing import Dict, Optional, Union, Callable, Any, List, Tuple, TYPE_CHECKING + +if TYPE_CHECKING: + from typing import Self from loguru import logger from nonebot import get_plugin_config, get_driver @@ -26,7 +29,7 @@ class DGLabPlayClient: :param client: pydglab-ws 的终端对象 """ - def __init__(self, user_id: str, destroy_callback: Callable[[Self], Any], client: DGLabClient = None): + def __init__(self, user_id: str, destroy_callback: Callable[["Self"], Any], client: DGLabClient = None): self.user_id = user_id self.client: Optional[DGLabClient] = client self._destroy_callback = destroy_callback @@ -40,7 +43,7 @@ def __init__(self, user_id: str, destroy_callback: Callable[[Self], Any], client self.register_finished_lock = asyncio.Lock() self.bind_finished_lock = asyncio.Lock() - async def __aenter__(self) -> Self: + async def __aenter__(self) -> "Self": for lock in self.register_finished_lock, self.bind_finished_lock: await lock.acquire() self.fetch_task = asyncio.create_task(self._serve()) diff --git a/nonebot_plugin_dg_lab_play/config.py b/nonebot_plugin_dg_lab_play/config.py index bd6a45b..7da6018 100644 --- a/nonebot_plugin_dg_lab_play/config.py +++ b/nonebot_plugin_dg_lab_play/config.py @@ -1,7 +1,10 @@ import ssl from functools import cached_property from pathlib import Path -from typing import Optional, Self, Any +from typing import Optional, Any, TYPE_CHECKING + +if TYPE_CHECKING: + from typing import Self from loguru import logger from nonebot import get_driver @@ -71,7 +74,7 @@ def server_ssl_context(self) -> Optional[ssl.SSLContext]: return None @model_validator(mode="after") - def validate_config(self) -> Self: + def validate_config(self) -> "Self": if self.remote_server: if not self.remote_server_uri: logger.error("启用了 remote_server,但没有配置 remote_server_uri") @@ -97,7 +100,7 @@ def validate_config(self) -> Self: raise PydanticCustomError return self - def validate_local_server_publish_uri(self) -> Self: + def validate_local_server_publish_uri(self) -> "Self": if (not self.remote_server and self.local_server_publish_uri == self.model_fields["local_server_publish_uri"].default): logger.warning(