Use functools.wraps instead of decorator#766
Use functools.wraps instead of decorator#766Pliner wants to merge 7 commits intoprometheus:masterfrom
Conversation
|
|
||
| return decorate(f, wrapped) | ||
| return f(*args, **kwargs) | ||
| return wrapped # type: ignore |
There was a problem hiding this comment.
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. |
| raise TypeError | ||
|
|
||
| self.assertEqual((["r"], None, None, None), getargspec(f)) | ||
| self.assertEqual("(r)", str(inspect.signature(f))) |
There was a problem hiding this comment.
I'm not sure these checks are relevant now: it could be worth ditching them.
551660d to
fe2a233
Compare
csmarchbanks
left a comment
There was a problem hiding this comment.
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?
938b988 to
d357585
Compare
Signed-off-by: Yury Pliner <yury.pliner@gmail.com> Signed-off-by: Iurii Pliner <yury.pliner@gmail.com>
python/mypy#1927 Signed-off-by: Yury Pliner <yury.pliner@gmail.com> Signed-off-by: Iurii Pliner <yury.pliner@gmail.com>
Signed-off-by: Yury Pliner <yury.pliner@gmail.com> Signed-off-by: Iurii Pliner <yury.pliner@gmail.com>
Signed-off-by: Yury Pliner <yury.pliner@gmail.com> Signed-off-by: Iurii Pliner <yury.pliner@gmail.com>
Signed-off-by: Yury Pliner <yury.pliner@gmail.com> Signed-off-by: Iurii Pliner <yury.pliner@gmail.com>
29afda4 to
d9aae14
Compare
Signed-off-by: Iurii Pliner <yury.pliner@gmail.com>
53b6afb to
b631c0e
Compare
Hey @csmarchbanks, Sorry for the delayed for 2 years response. I have investigated the mentioned downsides of
It doesn't seem to be relevant for this library, because they are passed as it is in all usecases.
It is true and might be relevant, however:
So, as part of this PR I have added a proper typing for decorators. Unfortunately, PS I don't know your opinion about this additional dependency, but it might be reasonable for the benefits we will get from the proper annotations, considering this extra dependency is only for 3.9. |
|
Hi @csmarchbanks, I am sorry for pinging you... Could you have a look on my last reply please? 🙏🏻 |
Just a small cleanup: only 3.9+ is supported, so it looks fine to switch to
functools.wraps.