For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Why is there no super().__init__() call when sub -classing backtrader objects?



  • I don't understand why there is no super call in derived class' __init__ method. It seems confusing when the examples start referencing attributes that haven't been defined such as self.data


  • administrators

    backtrack would have been a nice name now that I consider it, but it was finally decided to go with backtrader. Plus the domain for the former was taken (lack of consideration) by a railway company and the latter was fully free.

    There is no super().__init__ (or the Python 2.7 generic variant super(self.__class__, self).__init__()) because it was decided that the base objects from which end users will subclass wouldn't have __init__.

    You can still invoke super().__init__(), but it will just go all the way up to the standard Python object.__init__, which by itself does nothing.

    @jamespeterschinner said in Why is there no super().__init__() call when sub -classing backtrack objects?:

    It seems confusing when the examples start referencing attributes that haven't been defined such as self.data

    The point is to have you typing less and not having to pass parameters back and forth and calling unneeded methods.

    backtrader features a metaclass-machinery which does all the work in the background. The documentation already states that those things are available.



  • Thanks for the answer. I fixed the title from backtrack to backtrader. Yes, I have read the docs, I will read it again with this in mind. Ta