-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Overloaded function signatures overlap with incompatible return types, class and Callable #1941
Comments
You've nailed the reason for the overlap: f(A) matches both variants. (For other reasons it's important to accept classes when a callable is needed.) Note that mypy's I think we should close this issue as "won't fix". However maybe we need to change the wording in PEP 484 to call out this behavior more. I've opened python/typing#253 to serve that discussion. Feel free to participate! |
Hum, I see, then IMO, PEP 484 should demand that, rather than merging every alternatives, force the mypy to find the "most accurate" type description; so that a general case can be written, and have some specific cases. For example, having a @overload
def __getitem__(self, k: slice) -> List[_V]: ... # specific
@overload
def __getitem__(self, k: _K) -> _V: ... # generic For now, let's close it. |
(FWIW, I think the tradition is to list the special cases first and the general case last.) |
(Haha, yeah, that's more readable in a way, updated the comment, now it looks nicer!) |
Mypy lets you vary the return type even if multiple variants match if your signatures are ordered from narrower to more general. For example, this should be fine:
This would be a problem, though:
|
@JukkaL But in the current case, it is not working, I tried reordering the overload definition but it doesn't help. From what you wrote, I would have though that the overload for |
If |
The original problem looks like the second thing:
… mypy currently assumes that `Callable` can overlap with anything
|
gives
which I don't understand. There is no overlap (expect that
A
is also aCallable
), so, why the message?The text was updated successfully, but these errors were encountered: