mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 20:45:06 +08:00
remove some TYPE_CHECKING
This commit is contained in:
parent
86cb098b3d
commit
2340916570
|
@ -1,6 +1,6 @@
|
||||||
# Python 兼容版本 3.8+
|
# Python 兼容版本 3.8+
|
||||||
|
|
||||||
from typing import Callable, Tuple
|
from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ica.rs
|
ica.rs
|
||||||
|
@ -9,9 +9,9 @@ pub type UserId = i64;
|
||||||
pub type MessageId = String;
|
pub type MessageId = String;
|
||||||
"""
|
"""
|
||||||
class IcaType:
|
class IcaType:
|
||||||
RoomId = int
|
RoomId = NewType('RoomId', int)
|
||||||
UserId = int
|
UserId = NewType('UserId', int)
|
||||||
MessageId = str
|
MessageId = NewType('MessageId', str)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tailchat.rs
|
tailchat.rs
|
||||||
|
@ -21,12 +21,14 @@ pub type UserId = String;
|
||||||
pub type MessageId = String;
|
pub type MessageId = String;
|
||||||
"""
|
"""
|
||||||
class TailchatType:
|
class TailchatType:
|
||||||
GroupId = str
|
GroupId = NewType('GroupId', str)
|
||||||
ConverseId = str
|
ConverseId = NewType('ConverseId', str)
|
||||||
UserId = str
|
UserId = NewType('UserId', str)
|
||||||
MessageId = str
|
MessageId = NewType('MessageId', str)
|
||||||
|
|
||||||
class IcaStatus:
|
if TYPE_CHECKING:
|
||||||
|
|
||||||
|
class IcaStatus:
|
||||||
"""
|
"""
|
||||||
ica状态信息
|
ica状态信息
|
||||||
此类并不存储信息, 所有方法都是实时获取
|
此类并不存储信息, 所有方法都是实时获取
|
||||||
|
@ -60,11 +62,11 @@ class IcaStatus:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class IcaReplyMessage:
|
class IcaReplyMessage:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class IcaSendMessage:
|
class IcaSendMessage:
|
||||||
@property
|
@property
|
||||||
def content(self) -> str:
|
def content(self) -> str:
|
||||||
...
|
...
|
||||||
|
@ -86,12 +88,12 @@ class IcaSendMessage:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class IcaDeleteMessage:
|
class IcaDeleteMessage:
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class IcaNewMessage:
|
class IcaNewMessage:
|
||||||
"""
|
"""
|
||||||
Icalingua 接收到新消息
|
Icalingua 接收到新消息
|
||||||
"""
|
"""
|
||||||
|
@ -134,7 +136,7 @@ class IcaNewMessage:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class IcaClient:
|
class IcaClient:
|
||||||
"""
|
"""
|
||||||
Icalingua 的客户端
|
Icalingua 的客户端
|
||||||
"""
|
"""
|
||||||
|
@ -175,7 +177,7 @@ class IcaClient:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class TailchatReciveMessage:
|
class TailchatReciveMessage:
|
||||||
"""
|
"""
|
||||||
Tailchat 接收到的新消息
|
Tailchat 接收到的新消息
|
||||||
"""
|
"""
|
||||||
|
@ -208,7 +210,7 @@ class TailchatReciveMessage:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class TailchatSendingMessage:
|
class TailchatSendingMessage:
|
||||||
"""
|
"""
|
||||||
Tailchat 将要发送的信息
|
Tailchat 将要发送的信息
|
||||||
"""
|
"""
|
||||||
|
@ -233,7 +235,7 @@ class TailchatSendingMessage:
|
||||||
# """
|
# """
|
||||||
|
|
||||||
|
|
||||||
class TailchatClient:
|
class TailchatClient:
|
||||||
"""
|
"""
|
||||||
Tailchat 的客户端
|
Tailchat 的客户端
|
||||||
"""
|
"""
|
||||||
|
@ -258,12 +260,28 @@ class TailchatClient:
|
||||||
"""向日志中输出警告信息"""
|
"""向日志中输出警告信息"""
|
||||||
|
|
||||||
|
|
||||||
class ConfigData:
|
class ConfigData:
|
||||||
def __getitem__(self, key: str):
|
def __getitem__(self, key: str):
|
||||||
...
|
...
|
||||||
def have_key(self, key: str) -> bool:
|
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]
|
on_load = Callable[[IcaClient], None]
|
||||||
# def on_load(client: 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]]
|
on_config = Callable[[None], Tuple[str, str]]
|
||||||
|
|
||||||
CONFIG_DATA: ConfigData = ConfigData()
|
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from ica_typing import IcaNewMessage, IcaClient
|
||||||
|
from ica_typing import TailchatReciveMessage, TailchatClient
|
||||||
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:
|
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
||||||
if not (msg.is_from_self or msg.is_reply):
|
if not (msg.is_from_self or msg.is_reply):
|
||||||
|
|
|
@ -4,16 +4,9 @@ import subprocess
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from ica_typing import IcaNewMessage, IcaClient, ConfigData
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
CONFIG_DATA: ConfigData
|
||||||
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"
|
_version_ = "0.4.2"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user