How to use functools.wraps with method decorators #2128
Unanswered
sfc-gh-bchinn
asked this question in
Q&A
Replies: 1 comment
-
|
I don't think there is a good solution. Callable protocols and their interaction with methods is fundamentally broken in Python currently. I think this will need a solution in the typing spec before we can make any changes in typeshed. |
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.
-
Say I have a noop decorator:
Great. Now let's replace
Callablewith a Protocol defining__call__, say if we want to accessfunc.__name__or access specific args/kwargs being passed in:This fails on mypy with
Per #1040, we should add
__get__to return a Protocol with the post-bound signature:Now this fails with:
It works if I comment out
@functools.wraps(). For now, we can workaround it withBeta Was this translation helpful? Give feedback.
All reactions