-
Notifications
You must be signed in to change notification settings - Fork 106
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
Fix type annotations on template decorators #1211
Fix type annotations on template decorators #1211
Conversation
Use `Concatenate` to add the missing `self` parameter to the class methods annotated with `@_add_type_hints` in `TemplateDecoratorFuncsMixin`. Without this, mypy raises a `misc` error on usage, complaining that the method "does not accept self argument". Signed-off-by: Alice Purcell <alicederyn@gmail.com>
02f7c4e
to
884a6cc
Compare
@@ -474,7 +475,10 @@ def _add_type_hints( | |||
) -> Callable[ | |||
..., | |||
Callable[ | |||
PydanticKwargs, # this adds type hints to the underlying *library* function kwargs | |||
Concatenate[ | |||
object, # this is the `self` parameter |
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.
I tried to capture the correct class type from the decorated function, but couldn't find a way to do it that didn't break both mypy and pyright. I verified that both mypy and pyright are happy with object
. (Any
also seems to work if that's preferred.)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1211 +/- ##
=======================================
+ Coverage 81.7% 86.0% +4.2%
=======================================
Files 54 60 +6
Lines 4208 4040 -168
Branches 889 840 -49
=======================================
+ Hits 3439 3475 +36
+ Misses 574 392 -182
+ Partials 195 173 -22 ☔ View full report in Codecov by Sentry. |
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.
👍
Pull Request Checklist
Description of PR
Currently, mypy raises a
misc
error when using a decorator fromTemplateDecoratorFuncsMixin
, complaining that the method "does not accept self argument".This PR uses
Concatenate
to add the missing parameter.