-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
No error for identical overloaded functions #1879
Comments
Actually mypy's attitude towards overloading is more subtle -- it allows overlapping argument types as long as the return types match. PEP 484 is unclear about this. If you want to, you could help by adding some clarifying text to PEP 484 to the github.com/python/peps repo. We could also use some more words about this in mypy's own docs. |
Glad to help! I'll add the clarifying text soon. |
@gvanrossum I'm a bit confused about this; could you clarify the result of this scenario? Let's say I have this setup, where from typing import overload
class A(object):
@overload
def f(self) -> None:
print('Hello world 1')
@overload
def f(self) -> None:
print('Hello world 2')
class B(A):
def __init__(self) -> None:
self.f()
b = B() When I call |
Overloading is only for stubs. On Saturday, July 16, 2016, Shrey Desai [email protected] wrote:
--Guido (mobile) |
As of f61c2ba, mypy will now report the following error message for the above code snippet: "Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader". We could maybe improve the error message so it gives more customized feedback when the signatures are literally identical, but tbh I think this is clear enough. Feel free to reopen if anybody disagrees. |
Mypy doesn't raise any errors for this set up:
By definition, overloaded methods follow the "same name, different parameters" mantra, so allowing two identical overloaded methods should not be allowed.
This could get ugly when a base class inherits from the abstract class; there would be no guarantee the right function would be called.
The text was updated successfully, but these errors were encountered: