Feature: 为子依赖添加 PEP593 Annotated 支持 (#1832)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Johnny Hsieh
2023-03-22 20:54:46 +08:00
committed by GitHub
parent 9afaf3d516
commit 3e92fccd4e
3 changed files with 59 additions and 13 deletions

View File

@ -1,4 +1,5 @@
from dataclasses import dataclass
from typing_extensions import Annotated
from nonebot import on_message
from nonebot.params import Depends
@ -47,3 +48,17 @@ async def depends_cache(y: int = Depends(dependency, use_cache=True)):
async def class_depend(c: ClassDependency = Depends()):
return c
async def annotated_depend(x: Annotated[int, Depends(dependency)]):
return x
async def annotated_class_depend(c: Annotated[ClassDependency, Depends()]):
return c
async def annotated_prior_depend(
x: Annotated[int, Depends(lambda: 2)] = Depends(dependency)
):
return x