Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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?

    General Code/Help
    2
    3
    583
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jamespeterschinner
      jamespeterschinner last edited by jamespeterschinner

      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

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        • Docs - Platform Concepts
        • Docs - Operating the platform
        • Docs - Strategy
        1 Reply Last reply Reply Quote 0
        • jamespeterschinner
          jamespeterschinner last edited by

          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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors