Feature: 支持 PEP 695 类型别名 (#3621)

This commit is contained in:
Ju4tCode
2025-08-07 14:54:22 +08:00
committed by GitHub
parent 56f52f2c9f
commit 0d8b81614a
16 changed files with 232 additions and 9 deletions

View File

@ -0,0 +1,7 @@
from pathlib import Path
from nonebot import load_plugins
_sub_plugins = set()
_sub_plugins |= load_plugins(str(Path(__file__).parent))

View File

@ -0,0 +1,10 @@
from typing import Annotated
from nonebot.adapters import Message
from nonebot.params import Arg
type AliasedArg = Annotated[Message, Arg()]
async def aliased_arg(key: AliasedArg) -> Message:
return key

View File

@ -0,0 +1,7 @@
from nonebot.adapters import Bot
type AliasedBot = Bot
async def get_aliased_bot(b: AliasedBot) -> Bot:
return b

View File

@ -0,0 +1,21 @@
from typing import Annotated
from nonebot import on_message
from nonebot.params import Depends
test_depends = on_message()
runned = []
def dependency():
runned.append(1)
return 1
type AliasedDepends = Annotated[int, Depends(dependency)]
@test_depends.handle()
async def aliased_depends(x: AliasedDepends):
return x

View File

@ -0,0 +1,7 @@
from nonebot.adapters import Event
type AliasedEvent = Event
async def aliased_event(e: AliasedEvent) -> Event:
return e

View File

@ -0,0 +1,5 @@
type AliasedException = Exception
async def aliased_exc(e: AliasedException) -> Exception:
return e

View File

@ -0,0 +1,7 @@
from nonebot.matcher import Matcher
type AliasedMatcher = Matcher
async def aliased_matcher(m: AliasedMatcher) -> Matcher:
return m

View File

@ -0,0 +1,7 @@
from nonebot.typing import T_State
type AliasedState = T_State
async def aliased_state(x: AliasedState) -> T_State:
return x