Cloud Stack Ninja

The following inheritance structure satisfies the Liskov Substitution Principle (i.e., in this case, accepting any kwargs and not accepting any non-keyword args).

class Parent:
    def mymethod(self, **kwargs) -> None:
        print("Called Parent mymethod")
    
class Child(Parent):
    def mymethod(self, *, arg1: int, **kwargs) -> None:
        print("Called Child mymethod")

However, mypy produces an error:

error: Signature of "mymethod" incompatible with supertype "Parent"

Why?



Read more here: https://stackoverflow.com/questions/64396532/mypy-produces-incompatible-signature-error-but-liskov-substitution-principle-is

Content Attribution

This content was originally published by Victor Kostyuk at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: