I'm have a decorator that I want to use to decorate class methods. In the following example, the @mydec decorator works fine on its own, however it does not preserve the function signature when using help() or pydoc. In order to fix this, I looked at using @decorator python-decorator package:
import functools
import decorator
@decorator.decorator
def mydec(func):
@functools.wraps(func)
def inner(cls, *args, **kwargs):
# do some stuff
return func(cls, *args, **kwargs)
return inner
class Foo(object):
@classmethod
@mydec
def bar(cls, baz='test', qux=None):
print (baz, qux)
Foo.bar()
Unfortunately, this results in the following exception:
Traceback (most recent call last):
File "/tmp/test.py", line 21, in <module>
Foo.bar()
File "<string>", line 2, in bar
TypeError: mydec() takes exactly 1 argument (4 given)