Merge branch 'nonebot:dev' into dev

This commit is contained in:
AkiraXie 2022-02-04 15:14:06 +08:00 committed by GitHub
commit 4e1e0e98b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -36,10 +36,10 @@ from nonebot.typing import (
if TYPE_CHECKING: if TYPE_CHECKING:
from nonebot.adapters import Bot, Event from nonebot.adapters import Bot, Event
_event_preprocessors: Set[Dependent[None]] = set() _event_preprocessors: Set[Dependent[Any]] = set()
_event_postprocessors: Set[Dependent[None]] = set() _event_postprocessors: Set[Dependent[Any]] = set()
_run_preprocessors: Set[Dependent[None]] = set() _run_preprocessors: Set[Dependent[Any]] = set()
_run_postprocessors: Set[Dependent[None]] = set() _run_postprocessors: Set[Dependent[Any]] = set()
EVENT_PCS_PARAMS = [ EVENT_PCS_PARAMS = [
params.DependParam, params.DependParam,
@ -72,7 +72,7 @@ RUN_POSTPCS_PARAMS = [
def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor: def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
"""事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。""" """事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。"""
_event_preprocessors.add( _event_preprocessors.add(
Dependent[None].parse(call=func, allow_types=EVENT_PCS_PARAMS) Dependent[Any].parse(call=func, allow_types=EVENT_PCS_PARAMS)
) )
return func return func
@ -80,7 +80,7 @@ def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor: def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
"""事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。""" """事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。"""
_event_postprocessors.add( _event_postprocessors.add(
Dependent[None].parse(call=func, allow_types=EVENT_PCS_PARAMS) Dependent[Any].parse(call=func, allow_types=EVENT_PCS_PARAMS)
) )
return func return func
@ -88,7 +88,7 @@ def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor: def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
"""运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。""" """运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。"""
_run_preprocessors.add( _run_preprocessors.add(
Dependent[None].parse(call=func, allow_types=RUN_PREPCS_PARAMS) Dependent[Any].parse(call=func, allow_types=RUN_PREPCS_PARAMS)
) )
return func return func
@ -96,7 +96,7 @@ def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor: def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:
"""运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。""" """运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。"""
_run_postprocessors.add( _run_postprocessors.add(
Dependent[None].parse(call=func, allow_types=RUN_POSTPCS_PARAMS) Dependent[Any].parse(call=func, allow_types=RUN_POSTPCS_PARAMS)
) )
return func return func

View File

@ -44,18 +44,18 @@ def overrides(InterfaceClass: object) -> Callable[[T_Wrapped], T_Wrapped]:
T_State = Dict[Any, Any] T_State = Dict[Any, Any]
"""事件处理状态 State 类型""" """事件处理状态 State 类型"""
T_BotConnectionHook = Callable[["Bot"], Awaitable[None]] T_BotConnectionHook = Callable[["Bot"], Awaitable[Any]]
"""Bot 连接建立时钩子函数""" """Bot 连接建立时钩子函数"""
T_BotDisconnectionHook = Callable[["Bot"], Awaitable[None]] T_BotDisconnectionHook = Callable[["Bot"], Awaitable[Any]]
"""Bot 连接断开时钩子函数""" """Bot 连接断开时钩子函数"""
T_CallingAPIHook = Callable[["Bot", str, Dict[str, Any]], Awaitable[None]] T_CallingAPIHook = Callable[["Bot", str, Dict[str, Any]], Awaitable[Any]]
"""`bot.call_api` 钩子函数""" """`bot.call_api` 钩子函数"""
T_CalledAPIHook = Callable[ T_CalledAPIHook = Callable[
["Bot", Optional[Exception], str, Dict[str, Any], Any], Awaitable[None] ["Bot", Optional[Exception], str, Dict[str, Any], Any], Awaitable[Any]
] ]
"""`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result""" """`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result"""
T_EventPreProcessor = Callable[..., Union[None, Awaitable[None]]] T_EventPreProcessor = Callable[..., Union[Any, Awaitable[Any]]]
"""事件预处理函数 EventPreProcessor 类型 """事件预处理函数 EventPreProcessor 类型
依赖参数: 依赖参数:
@ -66,7 +66,7 @@ T_EventPreProcessor = Callable[..., Union[None, Awaitable[None]]]
- StateParam: State 对象 - StateParam: State 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_EventPostProcessor = Callable[..., Union[None, Awaitable[None]]] T_EventPostProcessor = Callable[..., Union[Any, Awaitable[Any]]]
"""事件预处理函数 EventPostProcessor 类型 """事件预处理函数 EventPostProcessor 类型
依赖参数: 依赖参数:
@ -77,7 +77,7 @@ T_EventPostProcessor = Callable[..., Union[None, Awaitable[None]]]
- StateParam: State 对象 - StateParam: State 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_RunPreProcessor = Callable[..., Union[None, Awaitable[None]]] T_RunPreProcessor = Callable[..., Union[Any, Awaitable[Any]]]
"""事件响应器运行前预处理函数 RunPreProcessor 类型 """事件响应器运行前预处理函数 RunPreProcessor 类型
依赖参数: 依赖参数:
@ -89,7 +89,7 @@ T_RunPreProcessor = Callable[..., Union[None, Awaitable[None]]]
- MatcherParam: Matcher 对象 - MatcherParam: Matcher 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_RunPostProcessor = Callable[..., Union[None, Awaitable[None]]] T_RunPostProcessor = Callable[..., Union[Any, Awaitable[Any]]]
"""事件响应器运行前预处理函数 RunPostProcessor 类型 """事件响应器运行前预处理函数 RunPostProcessor 类型
依赖参数: 依赖参数: