Child classes do not call the `__init__` method of the base class
Zarr version
v3
Description
I think this could and should be fixed in most cases:
-
core.buffer.gpu.Buffer.__init__does not callcore.buffer.core.Buffer.__init__ -
core.buffer.gpu.NDBuffer.__init__does not callcore.buffer.core.NDBuffer.__init__ -
storage.logging.LoggingStore.__init__does not callabc.store.Store.__init__ - ...
Do you agree?
Steps to reproduce
Full list of occurrences available here:
- https://app.deepsource.com/gh/DimitriPapadopoulos/zarr-python/issue/PYL-W0231/occurrences
storage.logging.LoggingStore.init does not call abc.store.Store.init
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__:
self._is_open = False
self._mode = AccessMode.from_literal(mode)
which the child class does not initialise in LoggingStore.__init__:
self._store = store
self.counter = defaultdict(int)
self.log_level = log_level
self.log_handler = log_handler
self._configure_logger(log_level, log_handler)
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?