クラスを定義するときに関数をラップしようとしています。このクラスのインスタンスでメソッドを使用します
以下は動作するコードです
class A(object):
def __init__(self):
pass
@self_decorator
def to_be_decorated(self):
pass
def self_decorator(fn):
from functools import wraps
@wraps(fn)
def wrapper(*args, **kwargs):
self = args[0]
return self.app.route('/twip')(fn(*args, **kwargs))
return wrapper
私が実際に取得しようとしているもの:
class A(object):
def __init__(self):
self.app = APP()
@self.app.wrapper_function # which apparently doesn't work
def to_be_decorated(self):
pass
それで、私の飾り方はうまくいくのでしょうか?