I’ve noticed that every examples and docs and references about backtrader never call super(ClassName, self).init() in derived class’s construction function, which is different from common use. For example, when I want to define a custom Module in Pytorch, it would look like:
class MyModule(torch.nn.Module):
def init(self):
super(MyModule, self).init()
”’
some logic
”’
'''
other functions like forward(self)
'''
But in backtrader, for example I define a custom Strategy, it looks like:
class MyStrategy(backtrader.Strategy):
def init(self):
self.sma = backtrader.indicators.SimpleMovingAverage(period=15)
'''
other functions like start(self), next(self), prenext(self)
'''
I wonder why is that.
1、Why can we not calling super(ClassName, self).init() in defining Class derived from backtrader’s class? I know backtrader is based on metaclass programming, is it because of this? If so, how?
2、Can I or Should I manually call super(ClassName, self).init() in derived class’s init(self) and why? If I shouldn’t but I did, what consequences would be caused?
I have tried manually call super(ClassName, self).init() in derived class’s init(self) but no consequences have been caused as far as I can tell, is it true?
Tong ZongYang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.