|
|
|
|
|
by scoutoss11235
3608 days ago
|
|
For what it's worth, the classmethod issue that concerns the author is mostly a non-issue if you apply your decorator before you wrap your function in a classmethod: In [1]: def my_decorator(f):
...: def wrapped(*args, **kwargs):
...: print("wrapping %s" % f.__name__)
...: return f(*args, **kwargs)
...: return wrapped
...:
In [2]: class Foo:
...: @classmethod
...: @my_decorator
...: def meth(cls, x, y):
...: return x + y
...:
In [3]: Foo.meth(1, 2)
wrapping meth
Out[3]: 3
This works because the user-defined decorator gets applied to the underlying function before it gets wrapped in a classmethod object (which doesn't supply the desired __name__ attribute).The signature introspection issue is real, and dealing with it in full generality requires a fair amount of work, especially if you want to be compatible with python 2 and python 3. |
|