2023-06-11 15:33:33 +08:00
|
|
|
from typing import Union, TypeVar
|
2022-05-22 19:42:30 +08:00
|
|
|
|
2021-12-20 00:28:02 +08:00
|
|
|
from nonebot.adapters import Bot
|
|
|
|
|
|
|
|
|
2022-03-20 19:40:43 +08:00
|
|
|
async def get_bot(b: Bot) -> Bot:
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
2024-05-09 15:08:49 +08:00
|
|
|
async def postpone_bot(b: "Bot") -> Bot:
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
2022-05-22 19:42:30 +08:00
|
|
|
async def legacy_bot(bot):
|
|
|
|
return bot
|
|
|
|
|
|
|
|
|
2024-02-06 12:48:23 +08:00
|
|
|
async def not_legacy_bot(bot: int): ...
|
2022-05-22 19:42:30 +08:00
|
|
|
|
|
|
|
|
2024-02-06 12:48:23 +08:00
|
|
|
class FooBot(Bot): ...
|
2022-03-20 19:40:43 +08:00
|
|
|
|
|
|
|
|
2022-05-22 19:42:30 +08:00
|
|
|
async def sub_bot(b: FooBot) -> FooBot:
|
2021-12-20 00:28:02 +08:00
|
|
|
return b
|
2022-05-22 19:42:30 +08:00
|
|
|
|
|
|
|
|
2024-02-06 12:48:23 +08:00
|
|
|
class BarBot(Bot): ...
|
2022-05-22 19:42:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
async def union_bot(b: Union[FooBot, BarBot]) -> Union[FooBot, BarBot]:
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
2023-06-11 15:33:33 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-02-06 12:48:23 +08:00
|
|
|
async def not_bot(b: Union[int, Bot]): ...
|