-
-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: 优先使用 Annotated
的最后一个子依赖
#2360
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2360 +/- ##
==========================================
+ Coverage 90.77% 90.81% +0.03%
==========================================
Files 46 46
Lines 3424 3428 +4
==========================================
+ Hits 3108 3113 +5
+ Misses 316 315 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
🚀 Deployed on https://deploy-preview-2360--nonebot2.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
当前的
Annotated
子依赖支持优先使用 metadata 中的第一个子依赖。此 PR 将行为更改成优先使用 metadata 中的最后一个子依赖。
借助嵌套
Annotated
会被展平,metadata 顺序由最内层向外的特性(assert Annotated[Annotated[int, ValueRange(3, 10)], ctype("char")] == Annotated[int, ValueRange(3, 10), ctype("char")]
),可以实现Annotated
子依赖的复用:假设上游提供一个
User
子依赖在下游,可以重写
User
的依赖注入逻辑,而复用User
的类型标注:参见:
Annotated
支持 #1832