だからここに私が持っているものがあります:
抽象クラス:
class DataWrapper(object):
def decorator(f):
def preprocess(*args, **kwargs):
return f(*args, **kwargs)
return preprocess
@decorator
def datamethod1(self, ..): ...
@decorator
def datamethod2(self, ..): ...
継承クラス:
class DataManipulation(DataWrapper):
def __init__(self, ..): ..
def decorator(f):
print 'here'
def preprocess(*args, **kwargs):
ret = f(*args, **kwargs)
return preprocess
基本的に、さまざまなクラスで使用される一般的なデータ メソッド (DataWrapper で定義) がたくさんあります。デコレータを定義して、返される前にデータに対して前/後処理を実行できるようにします。これは、DataWrapper でプレースホルダーとして定義されています。
残念ながら、継承されたクラスでデコレータを定義しようとしても、デコレータはオーバーライドされません。つまり、「ここ」は印刷されていません。
これを見て、継承されたクラスにオーバーライドデコレータを追加しようとしましたが、エラーはありませんが、「ここ」はまだ出力されていません。
誰にも提案はありますか?