-
Notifications
You must be signed in to change notification settings - Fork 799
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
Use functools.wraps instead of decorator #766
base: master
Are you sure you want to change the base?
Use functools.wraps instead of decorator #766
Conversation
Signed-off-by: Yury Pliner <[email protected]>
python/mypy#1927 Signed-off-by: Yury Pliner <[email protected]>
Signed-off-by: Yury Pliner <[email protected]>
|
||
return decorate(f, wrapped) | ||
return f(*args, **kwargs) | ||
return wrapped # type: ignore |
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.
It looks like there are two options for now: ignore or cast.
PS In python 3.10 it was resolved via https://docs.python.org/3/library/typing.html#typing.ParamSpec.
@csmarchbanks Could you look on it please? Thanks. |
@@ -54,7 +54,7 @@ def f(r): | |||
else: | |||
raise TypeError | |||
|
|||
self.assertEqual((["r"], None, None, None), getargspec(f)) | |||
self.assertEqual("(r)", str(inspect.signature(f))) |
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'm not sure these checks are relevant now: it could be worth ditching them.
Signed-off-by: Yury Pliner <[email protected]>
551660d
to
fe2a233
Compare
Signed-off-by: Yury Pliner <[email protected]>
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.
Hmm, I am not super familiar with functools.wraps
but I see some disagreement around if it actually preserves the signature, for example: https://stackoverflow.com/questions/13907644/decorator-module-vs-functools-wraps/55363013#55363013. Are there some recent posts around functools.wraps
for 3.6+ that fully preserve the signature?
Just a small cleanup: only 3.6+ is supported, so it looks fine to switch to
functools.wraps
.