mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +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 Bot
|
||||
|
||||
@ -31,5 +31,19 @@ async def union_bot(b: Union[FooBot, BarBot]) -> Union[FooBot, BarBot]:
|
||||
return b
|
||||
|
||||
|
||||
B = TypeVar("B", bound=Bot)
|
||||
|
||||
|
||||
async def generic_bot(b: B) -> B:
|
||||
return b
|
||||
|
||||
|
||||
CB = TypeVar("CB", Bot, None)
|
||||
|
||||
|
||||
async def generic_bot_none(b: CB) -> CB:
|
||||
return b
|
||||
|
||||
|
||||
async def not_bot(b: Union[int, Bot]):
|
||||
...
|
||||
|
Reference in New Issue
Block a user