+ 2
Help in Python decorator
What do "functools.wrap" in Line 2 ? can explaine it 🙏 def decorator(func): @functools.wraps(func) def wrapper_decorator(*args, **kwargs): # Do something before value = func(*args, **kwargs) # Do something after return value return wrapper_decorator
4 ответов
+ 4
It keeps the specific attributes of func that will normally be shadowed by the wrapper.
Eg the name of func
+ 3
That's partially possible, but how about help string, signature,...
you can do it for each one .... or functools.wrap
+ 3
yes.. 😅 I didn't think about it.
Thank you for the response.
+ 2
So what's the advantage of this?
just keep the name?
Why don't we do this =>
"wrapper_decorator.__name__ = func.__name__ " instead import functools?