Currently, functools.wraps
fail for classes:
class A:
pass
@functools.wraps(A)
class B:
pass
Fail with:
AttributeError: 'mappingproxy' object has no attribute 'update'
This is because functools.update_wrapper
try to mutate the __dict__
, which is not possible for class.
It would be relatively easy to fix by using setattr(cls,...)
rather than mutating cls.__dict__
:
def update_wrapper(wrapper, wrapped):
"""Same as `functools.update_wrapper`, but supports class."""
for name in functools.WRAPPER_ASSIGNMENTS:
try:
value = getattr(wrapped, name)
except AttributeError:
pass
else:
setattr(wrapper, name, value)
return wrapper