mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-26 07:41:20 +00:00
✨ Feature: 依赖注入支持 Generic TypeVar 和 Matcher 重载 (#2089)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from typing import Union
|
||||
from typing import Union, TypeVar
|
||||
|
||||
from nonebot.adapters import Event, Message
|
||||
from nonebot.params import EventToMe, EventType, EventMessage, EventPlainText
|
||||
@ -32,6 +32,20 @@ async def union_event(e: Union[FooEvent, BarEvent]) -> Union[FooEvent, BarEvent]
|
||||
return e
|
||||
|
||||
|
||||
E = TypeVar("E", bound=Event)
|
||||
|
||||
|
||||
async def generic_event(e: E) -> E:
|
||||
return e
|
||||
|
||||
|
||||
CE = TypeVar("CE", Event, None)
|
||||
|
||||
|
||||
async def generic_event_none(e: CE) -> CE:
|
||||
return e
|
||||
|
||||
|
||||
async def not_event(e: Union[int, Event]):
|
||||
...
|
||||
|
||||
|
Reference in New Issue
Block a user