Slide 17
Slide 17 text
Wrapping class and static methods
class Class(object):
@function_wrapper
@classmethod
def cmethod(cls):
pass
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in Class
File "", line 2, in wrapper
File ".../functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'classmethod' object has no
attribute '__module__'
17
The first is that even if using functools.wraps() or
functools.update_wrapper() in your decorator, when the
decorator is applied around @classmethod or
@staticmethod, it will fail with an exception. This is
because the wrappers created by these, do not have
some of the attributes being copied. As it happens, this
is a Python 2 bug and it is fixed in Python 3 by ignoring
missing attributes.