なぜこれが私に始まったのかはわかりませんが、以下に示すように、別のコンテキストマネージャークラスのサブクラスであるコンテキストマネージャー準拠のクラスがある場合。__exit__ が close() を呼び出す「典型的な」モデルを示しました。私の質問は次のとおりです: bar.__exit__() は明示的に super(bar,self).__exit__(args) を呼び出す必要がありますか、または bar の close() は foo の close を呼び出す必要がありますか? この場合、ここで推奨されるモデルは何ですか?
class foo(object):
def __enter__(self):
pass
def __exit__(self,*exc_info):
self.close()
return False
def close(self):
pass
class bar(foo):
def __enter__(self):
pass
def __exit__(self,*exc_info):
self.close()
return False
def close(self):
super(bar,self).close() # is this the recommend model?
ありがとう。