OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Mypy method definition is incompatible with definition in base class

  • Thread starter Thread starter matt
  • Start date Start date
M

matt

Guest
I have a parent class that does something and two child classes that wrap a method in orthogonal ways. When I try to combine the two child classes, mypy complains with the following error.

Definition of "run" in base class "Foo" is incompatible with definition in base class "Bar"

How are the two classes "incompatible" and how do I modify my code to appease mypy? Can I do it without making

Code:
class Parent:
    def run(self, a, b):
        pass


class Foo(Parent):
    def run(self, a, b, foo=None, **kwargs):
        print('foo', foo)
        super().run(a, b, **kwargs)


class Bar(Parent):
    def run(self, a, b, bar=None, **kwargs):
        print('bar', bar)
        super().run(a, b, **kwargs)


class C(Foo, Bar):
    pass
<p>I have a parent class that does something and two child classes that wrap a method in orthogonal ways. When I try to combine the two child classes, mypy complains with the following error.</p>

<blockquote>
<p>Definition of "run" in base class "Foo" is incompatible with
definition in base class "Bar"</p>
</blockquote>

<p>How are the two classes "incompatible" and how do I modify my code to appease mypy? Can I do it without making</p>

<pre><code>class Parent:
def run(self, a, b):
pass


class Foo(Parent):
def run(self, a, b, foo=None, **kwargs):
print('foo', foo)
super().run(a, b, **kwargs)


class Bar(Parent):
def run(self, a, b, bar=None, **kwargs):
print('bar', bar)
super().run(a, b, **kwargs)


class C(Foo, Bar):
pass
</code></pre>
 

Latest posts

J
Replies
0
Views
1
jbowerbir
J
Top