Skip to content

Compatibility of method parameters of subclasses #424

Closed
@spkersten

Description

@spkersten

Consider these classes:

class X:
        pass
class Y(X):
        pass
class Z(Y):
        pass

class A:
        def f(self, x: Y) -> None:
                pass

class B(A):
        def f(self, x: Z) -> None:
                pass

Here mypy, correctly, gives a type error, saying that, in class B, the first argument of f is incompatible with supertype A.

Now consider this class:

class C(A):
        def f(self, x: X) -> None:
                pass

mypy reports the same type error as for B. Is that correct? In a statically typed language, the definition of C should be okay. I'm still not completely familiar with gradual typing, so maybe I'm missing something again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions