🏷️ Update BaseEvent typing

This commit is contained in:
Artin 2020-12-03 01:46:51 +08:00
parent 33bd9d0fb8
commit 8c5c02f040
2 changed files with 7 additions and 6 deletions

View File

@ -137,27 +137,27 @@ class BaseBot(abc.ABC):
raise NotImplementedError
T = TypeVar("T", dict, BaseModel)
T = TypeVar("T", bound=BaseModel)
class BaseEvent(abc.ABC, Generic[T]):
class BaseEvent(Generic[T], abc.ABC):
"""
Event 基类提供上报信息的关键信息其余信息可从原始上报消息获取
"""
def __init__(self, raw_event: T):
def __init__(self, raw_event: Union[dict, T]):
"""
:参数:
* ``raw_event: T``: 原始上报消息
"""
self._raw_event: T = raw_event
self._raw_event = raw_event
def __repr__(self) -> str:
return f"<Event {self.self_id}: {self.name} {self.time}>"
@property
def raw_event(self) -> T:
def raw_event(self) -> Union[dict, T]:
"""原始上报消息"""
return self._raw_event

View File

@ -1,4 +1,5 @@
from typing import Literal, Union
from typing import Literal
from nonebot.adapters import BaseEvent
from nonebot.typing import Optional