Skip to content

Child classes do not call the __init__ method of the base class #2378

Closed

Activity

  1. jhamman commented on Oct 15, 2024

    @jhamman
    Member

    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.

  2. DimitriPapadopoulos commented on Oct 16, 2024

    @DimitriPapadopoulos
    ContributorAuthor

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions