Optinal in Callable with self
#2285
Unanswered
ninanomenon
asked this question in
Q&A
Replies: 1 comment
-
|
The protocol should look somewhat like this (untested): class AuthWrapper[**P, R]:
def __call__(self, client: ApiClient, client_id: str | None = None, /, *args: P.args, **kwargs: P.kwargs) -> R: ...(The "self" here refers to the callable itself, not the client object.) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For a an complex API client I have build an decorator which injects a http session into the method inside a class.
The function inside the decorator looks ruffly like this:
The typing of the decorator is slightly wrong since the
wrapperfunction defines a default value ofNone. But I haven't found a way to tell my type checker that.The mypy docs say that Protocol classes are the correct way to type this, but I wasn't able with the
selfparameter. Can someone point me into the correct direction?Beta Was this translation helpful? Give feedback.
All reactions