Skip to content

Improve Liskov checks with overloads in subclass #15121

Open
@hauntsaninja

Description

@hauntsaninja

The following program is type safe:

from typing import overload

class A: ...
class B: ...

class Parent:
    def dst(self, x: A | B) -> int | None: ...

class Child(Parent):
    @overload
    def dst(self, x: A) -> int: ...
    @overload
    def dst(self, x: B) -> None: ...

This came up in python/typeshed#9862

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-typeshedAnything that blocks a typeshed changebugmypy got something wrongtopic-inheritanceInheritance and incompatible overrides

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions