Skip to content

Commit

Permalink
fix: 修復 py3.9 導入 Self 失敗
Browse files Browse the repository at this point in the history
  • Loading branch information
Ljzd-PRO committed May 21, 2024
1 parent cf05d03 commit 0b6736b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions nonebot_plugin_dg_lab_play/client_manager.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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())
Expand Down
9 changes: 6 additions & 3 deletions nonebot_plugin_dg_lab_play/config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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(
Expand Down

0 comments on commit 0b6736b

Please sign in to comment.