Skip to content

Inheriting overloaded signatures #5146

@Geggles

Description

@Geggles

Say we have a class Foo:

class Foo:
    @overload
    def fun(self, s:str) -> str:
        pass

    @overload
    def fun(self, i:int) -> int:
        pass

    def fun(self, x):
        pass

If we now add a subclass Bar like this:

class Bar(Foo):
    @overload
    def fun(self, s:str) -> str:
        pass

    @overload
    def fun(self, i:int) -> int:
        pass

    def fun(self, x):
        pass
Bar().fun([])

and run mypy on it without any flags, we get the expected
error: No overload variant of "fun" of "Bar" matches argument type "List[<nothing>]".
If however we don't copy the overloaded signatures,

class Bar(Foo):
    def fun(self, x):
        pass
Bar().fun([])

then mypy does not find any errors. Is this inteded behaviour? Is it not possible to find the overloaded signatures of the base classes statically? Am I not supposed to do this sort of thing in the first place?

> python -V
Python 3.6.2
> mypy -V
mypy 0.610+dev-eb1bb064d707ce05735ff6795df82126e75ea6ea

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions