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

Incompatible definition between base classes #2377

Closed
squiddy opened this issue Oct 29, 2016 · 2 comments
Closed

Incompatible definition between base classes #2377

squiddy opened this issue Oct 29, 2016 · 2 comments

Comments

@squiddy
Copy link

squiddy commented Oct 29, 2016

Sorry for the rather vague title, but I can't put it more precise. Find below a code example, I tried to keep it relevant for my use case. Note that, while the code shown is python3, the actual usage is in python2. Both versions behave identical though.

class Window:
    """
    Base class for all elements that act like windows, can be shown and hidden.
    """
    def show(self, **kwargs):
        # this is supposed to be implemented by subclasses
        raise NotImplementedError


class SpecialWidget:
    """
    Widget that shows things, like a table that is updated.
    """
    def show(self):
        # setup gui elements
        pass

    def update_things(self):
        pass


class FooWindow(SpecialWidget, Window): # <-- E: Definition of "show" in base class "SpecialWidget" is incompatible with definition in base class "Window"
    """
    A window that uses the GUI setup of SpecialWidget.
    """
    def update_things(self):
        pass

I fully understand the error, however, I'm at a loss on what to do about it. Obviously I could add **kwargs to Specialwidget.show, that gets rid of the error. But I don't really want to do that.

I tried to add my own show implementation in FooWindow:

    def show(self):
        SpecialWidget.show(self)

But that doesn't work. I also tried to have mypy ignore the definitions:

    def show(self): # type: ignore
        # setup gui elements
        pass

But that doesn't seem to be working either.

I'd appreciate any pointers, be it help with ignoring the error, fixing it or refactoring the code to avoid this issue.

@gvanrossum
Copy link
Member

I think this is a dupe of #1237. But I'm surprised the # type: ignore doesn't work.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 16, 2017

This gets rid of the error for me (the comment needs to be on the line where the error is reported):

class FooWindow(SpecialWidget, Window): # type: ignore

Closing this issue for now; feel free to reopen is this still doesn't address your issue.

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

3 participants