remove some TYPE_CHECKING

This commit is contained in:
shenjack-5600u 2024-06-09 20:01:44 +08:00
parent 86cb098b3d
commit 2340916570
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
3 changed files with 250 additions and 249 deletions

View File

@ -1,6 +1,6 @@
# Python 兼容版本 3.8+
from typing import Callable, Tuple
from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar
"""
ica.rs
@ -9,9 +9,9 @@ pub type UserId = i64;
pub type MessageId = String;
"""
class IcaType:
RoomId = int
UserId = int
MessageId = str
RoomId = NewType('RoomId', int)
UserId = NewType('UserId', int)
MessageId = NewType('MessageId', str)
"""
tailchat.rs
@ -21,10 +21,12 @@ pub type UserId = String;
pub type MessageId = String;
"""
class TailchatType:
GroupId = str
ConverseId = str
UserId = str
MessageId = str
GroupId = NewType('GroupId', str)
ConverseId = NewType('ConverseId', str)
UserId = NewType('UserId', str)
MessageId = NewType('MessageId', str)
if TYPE_CHECKING:
class IcaStatus:
"""
@ -264,6 +266,22 @@ class ConfigData:
def have_key(self, key: str) -> bool:
...
CONFIG_DATA: ConfigData = ConfigData()
else:
"""
正常 Import 的时候使用的类型定义
"""
IcaStatus = TypeVar("IcaStatus")
IcaReplyMessage = TypeVar("IcaReplyMessage")
IcaNewMessage = TypeVar("IcaNewMessage")
IcaSendMessage = TypeVar("IcaSendMessage")
IcaDeleteMessage = TypeVar("IcaDeleteMessage")
IcaClient = TypeVar("IcaClient")
TailchatReciveMessage = TypeVar("TailchatReciveMessage")
TailchatSendingMessage = TypeVar("TailchatSendingMessage")
TailchatClient = TypeVar("TailchatClient")
ConfigData = TypeVar("ConfigData")
on_load = Callable[[IcaClient], None]
# def on_load(client: IcaClient) -> None:
@ -282,5 +300,3 @@ on_tailchat_message = Callable[[TailchatClient, TailchatReciveMessage], None]
# ...
on_config = Callable[[None], Tuple[str, str]]
CONFIG_DATA: ConfigData = ConfigData()

View File

@ -1,13 +1,5 @@
from typing import TYPE_CHECKING, TypeVar
if TYPE_CHECKING:
from ica_typing import IcaNewMessage, IcaClient
from ica_typing import TailchatReciveMessage, TailchatClient
else:
IcaNewMessage = TypeVar("NewMessage")
IcaClient = TypeVar("IcaClient")
TailchatReciveMessage = TypeVar("TailchatReciveMessage")
TailchatClient = TypeVar("TailchatClient")
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
if not (msg.is_from_self or msg.is_reply):

View File

@ -4,16 +4,9 @@ import subprocess
from pathlib import Path
from typing import TYPE_CHECKING, TypeVar
if TYPE_CHECKING:
from ica_typing import IcaNewMessage, IcaClient, ConfigData
CONFIG_DATA: ConfigData
else:
CONFIG_DATA = None # type: ignore
IcaNewMessage = TypeVar("NewMessage")
IcaClient = TypeVar("IcaClient")
_version_ = "0.4.2"