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

Limitation of the current Class inheritance #23

Open
thomassajot opened this issue Oct 28, 2020 · 1 comment
Open

Limitation of the current Class inheritance #23

thomassajot opened this issue Oct 28, 2020 · 1 comment

Comments

@thomassajot
Copy link

thomassajot commented Oct 28, 2020

When adding the DataMixin class (PR: #14), the inheritence of most of the classes in the repo have not been set properly.
An failing example:

import ipywidgets
from jupyter_innotater.data import Innotation, TextInnotation, BoundingBoxInnotation

class ButtonInnotationExtended(Innotation):
    requires_data = False

    def __init__(self, icon, description, on_click=None, **kwargs):
        self.icon = icon
        self.description = description
        self.on_click_callback = on_click
        super().__init__(**kwargs)

    def on_click(self, callback, remove=False):
        self.button.on_click(callback, remove)

    def _create_widget(self):
        if not hasattr(self, "button"):
            self.button = ipywidgets.Button(description=self.description, layout=self.layout, icon=self.icon)
            if self.on_click_callback is not None:
                self.button.on_click(self.on_click_callback)
            return self.button
        return self.button

    def update_ui(self, uindex):
        pass

    def update_data(self, uindex):
        pass

Calling ButtonInnotationExtended(description='save', on_click=None, icon='save') would fail with the exception TypeError: object.__init__() takes exactly one argument (the instance to initialize).

After reading this very good blog posts: Python’s super() considered super! and Cooperative multiple-inheritance paradigm in python, it seems that there is a better way to propagate unknown arguments through the class inheritance tree.

@danlester
Copy link
Member

@thomassajot Thank you for making this issue.

I won't have a chance to have a proper look for a while. If you do get a chance to put together a PR then of course that would really help.

I think I have seen those articles in another context more recently actually, so it all makes some sense.

Dan

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