You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Child classes do not call the __init__ method of the base class #2378
This is the expected behavior. The LoggingStore wraps another Store object and the assumption is that this store called super().__init__(). I don't think it would make sense to call it again.
While the child class does not have to call super.__init__(), it is usually expected to.
In this specific case, LoggingStore inherits Store. If possible, LoggingStore.__init__ should call Store.__init__. That does seem possible and preferable here, as the base class initialises some private variables in Store.__init__:
Shouldn't the variables of the base class be initialised when creating a child class? I may be missing something, but then it could mean that the code is overly complex, breaking usual assumptions without any visible explanation.
Said otherwise, why have a non-empty __init__ in an abstract base class, if it is not called by child classes?
Activity
jhamman commentedon Oct 15, 2024
This is the expected behavior. The
LoggingStorewraps anotherStoreobject and the assumption is that this store calledsuper().__init__(). I don't think it would make sense to call it again.DimitriPapadopoulos commentedon Oct 16, 2024
While the child class does not have to call
super.__init__(), it is usually expected to.In this specific case,
LoggingStoreinheritsStore. If possible,LoggingStore.__init__should callStore.__init__. That does seem possible and preferable here, as the base class initialises some private variables inStore.__init__:which the child class does not initialise in
LoggingStore.__init__:Shouldn't the variables of the base class be initialised when creating a child class? I may be missing something, but then it could mean that the code is overly complex, breaking usual assumptions without any visible explanation.
Said otherwise, why have a non-empty
__init__in an abstract base class, if it is not called by child classes?