Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheriting overloaded signatures #5146

Closed
Geggles opened this issue Jun 5, 2018 · 2 comments
Closed

Inheriting overloaded signatures #5146

Geggles opened this issue Jun 5, 2018 · 2 comments

Comments

@Geggles
Copy link

Geggles commented Jun 5, 2018

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
@ilevkivskyi
Copy link
Member

Is this inteded behaviour?

Currently yes, you are supposed to repeat type signature in subclasses even if it is unchanged, otherwise all unannotated functions are not checked and all their args are given Any type, as per PEP 484. On one hand it is a bit "boring", on other hand explicit is better than explicit. There is already a proposal to switch to use superclass signature by default instead of defaulting to all Any python/typing#269 so I am closing this one as a duplicate.

@nateyoder
Copy link

Given that python/typing#269 was closed by saying that this should be a type checker specific decision does this mean that mypy has decided not to implement this feature or could this issue be reopened for discussion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants