mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-01 01:26:46 +00:00
✨ Feature: 支持 PEP 695 类型别名 (#3621)
This commit is contained in:
7
tests/python_3_12/plugins/aliased_param/__init__.py
Normal file
7
tests/python_3_12/plugins/aliased_param/__init__.py
Normal 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))
|
10
tests/python_3_12/plugins/aliased_param/param_arg.py
Normal file
10
tests/python_3_12/plugins/aliased_param/param_arg.py
Normal 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
|
7
tests/python_3_12/plugins/aliased_param/param_bot.py
Normal file
7
tests/python_3_12/plugins/aliased_param/param_bot.py
Normal file
@ -0,0 +1,7 @@
|
||||
from nonebot.adapters import Bot
|
||||
|
||||
type AliasedBot = Bot
|
||||
|
||||
|
||||
async def get_aliased_bot(b: AliasedBot) -> Bot:
|
||||
return b
|
21
tests/python_3_12/plugins/aliased_param/param_depend.py
Normal file
21
tests/python_3_12/plugins/aliased_param/param_depend.py
Normal 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
|
7
tests/python_3_12/plugins/aliased_param/param_event.py
Normal file
7
tests/python_3_12/plugins/aliased_param/param_event.py
Normal file
@ -0,0 +1,7 @@
|
||||
from nonebot.adapters import Event
|
||||
|
||||
type AliasedEvent = Event
|
||||
|
||||
|
||||
async def aliased_event(e: AliasedEvent) -> Event:
|
||||
return e
|
@ -0,0 +1,5 @@
|
||||
type AliasedException = Exception
|
||||
|
||||
|
||||
async def aliased_exc(e: AliasedException) -> Exception:
|
||||
return e
|
7
tests/python_3_12/plugins/aliased_param/param_matcher.py
Normal file
7
tests/python_3_12/plugins/aliased_param/param_matcher.py
Normal file
@ -0,0 +1,7 @@
|
||||
from nonebot.matcher import Matcher
|
||||
|
||||
type AliasedMatcher = Matcher
|
||||
|
||||
|
||||
async def aliased_matcher(m: AliasedMatcher) -> Matcher:
|
||||
return m
|
7
tests/python_3_12/plugins/aliased_param/param_state.py
Normal file
7
tests/python_3_12/plugins/aliased_param/param_state.py
Normal 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
|
Reference in New Issue
Block a user