Feature: 优先使用 Annotated 的最后一个子依赖 (#2360)

Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
This commit is contained in:
Bryan不可思议
2023-09-14 00:14:45 +08:00
committed by GitHub
parent 0030bf725e
commit 7aaa66c8ba
4 changed files with 37 additions and 3 deletions

View File

@ -142,7 +142,7 @@ class DependParam(Param):
if get_origin(param.annotation) is Annotated:
type_annotation, *extra_args = get_args(param.annotation)
depends_inner = next(
(x for x in extra_args if isinstance(x, DependsInner)), None
(x for x in reversed(extra_args) if isinstance(x, DependsInner)), None
)
# param default value takes higher priority
@ -462,7 +462,7 @@ class ArgParam(Param):
Required, key=param.default.key or param.name, type=param.default.type
)
elif get_origin(param.annotation) is Annotated:
for arg in get_args(param.annotation):
for arg in get_args(param.annotation)[:0:-1]:
if isinstance(arg, ArgInner):
return cls(Required, key=arg.key or param.name, type=arg.type)