44适配器开发者可以根据需要实现此模块中消息类的子类或定义与此不同的消息类型,但建议若可行的话应尽量使用此模块中消息类的子类。
55"""
66
7+ import builtins
78from abc import ABC , abstractmethod
89from collections .abc import ItemsView , Iterator , KeysView , Mapping , ValuesView
9- from typing import ( # noqa: UP035
10- Any ,
11- Generic ,
12- Optional ,
13- SupportsIndex ,
14- Type ,
15- TypeVar ,
16- Union ,
17- overload ,
18- )
10+ from typing import Any , Generic , Optional , SupportsIndex , TypeVar , Union , overload
1911from typing_extensions import Self , override
2012
2113from pydantic import BaseModel , Field , GetCoreSchemaHandler
@@ -51,6 +43,7 @@ def __init__(self, *messages: BuildMessageType[MessageSegmentT]) -> None:
5143 Args:
5244 *messages: 可以被转化为消息的数据。
5345 """
46+ super ().__init__ ()
5447 segment_class = self .get_segment_class ()
5548 for message in messages :
5649 if isinstance (message , list ):
@@ -315,7 +308,7 @@ def _replace_str(self, old: str, new: str, count: int = -1) -> Self:
315308 return temp_msg
316309
317310
318- class MessageSegment (ABC , BaseModel , Mapping [str , Any ], Generic [MessageT ]):
311+ class MessageSegment (ABC , BaseModel , Mapping [str , Any ], Generic [MessageT ]): # pyright: ignore[reportUnsafeMultipleInheritance]
319312 """消息字段。
320313
321314 本类实现了所有 `Mapping` 类型的方法,这些方法全部是对 `data` 属性的操作。
@@ -332,7 +325,7 @@ class MessageSegment(ABC, BaseModel, Mapping[str, Any], Generic[MessageT]):
332325
333326 @classmethod
334327 @abstractmethod
335- def get_message_class (cls ) -> Type [MessageT ]: # noqa: UP006
328+ def get_message_class (cls ) -> builtins . type [MessageT ]:
336329 """获取消息类。
337330
338331 Returns:
0 commit comments