Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider making LindiH5pyFile a subclass of LindiH5pyGroup #38

Open
magland opened this issue Apr 4, 2024 · 1 comment
Open

Consider making LindiH5pyFile a subclass of LindiH5pyGroup #38

magland opened this issue Apr 4, 2024 · 1 comment

Comments

@magland
Copy link
Collaborator

magland commented Apr 4, 2024

          In h5py, `h5py.File` is a subclass of `h5py.Group`. Multiple inheritance is ugly but there is some code shared between `LindiH5pyFile` and `LindiH5pyGroup` that *I think* could be simplified by having `LindiH5pyFIle` inherit also from `LindiH5pyGroup`.

Originally posted by @rly in #28 (comment)

@magland magland changed the title Considure making LindiH5pyFile a subclass of LindiH5pyGroup Consider making LindiH5pyFile a subclass of LindiH5pyGroup Apr 4, 2024
@oruebel
Copy link

oruebel commented Apr 4, 2024

I think* could be simplified by having LindiH5pyFIle inherit also from LindiH5pyGroup

Just a note of caution, since both h5py.File and LindiH5pyGroup inherit from h5py.Group this would result not just in a simple multiple inheritance, but actually in a diamond inheritance pattern.

         h5py.Group
        /         \
       /           \
 h5py.File    LindiH5pyGroup
      \            /
       \          /
       LindiH5pyFile 

This pattern can lead to ambiguity in method and attribute resolution. This can certainly be done, but is something that should be done with great care.

Alternatively, since LindiH5pyFile already inherits from h5py.Group, would it be possible to factor out shared code from LindiH5pyGroup into utility functions that can be used in both places to avoid multiple inheritance?

Or if that doesn't work, would it be possible to factor out shared code in another class, e.g., LindiGroupBase (that would not have another base class). This would then still require multiple inheritance, since then LindiH5pyGroup would inherit from both h5py.Group and LindiGroupBase and LindiH5pyFile would inherit from h5py.File and LindiGroupBase, but it would avoid diamond inheritance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants