Skip to content
Discussion options

You must be logged in to vote

The problem is that the parent class accepts any object that is callable and can be passed any list of arguments. By the Liskov Substitution Principle (LSP), any subclass must also accept an object that is callable and can be passed any list of arguments. However, the child class in this case is much more restrictive. It requires that the callable parameter is an instance of a specific class (CallableClass).

Why is this a problem? Consider the following:

class Child(Parent):
    def test(self, callable: CallableClass) -> None:
        assert isinstance(callable, CallableClass)

def test_parent(p: Parent, c: Callable[..., None]):
    p.test(c)

test_parent(Child(), lambda: None)

It's impor…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yaminmaazou
Comment options

Answer selected by yaminmaazou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants