-
-
Notifications
You must be signed in to change notification settings - Fork 3k
overload with wrong return type is ignored #17857
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
Comments
But the type declaration you provided should be treated as an "or" statement. For example, int | str is regarded by mypy as either int or str. Sorry for being a bit naive, but would you mind explaining a bit more about the expected output you want so that I can help solve the problem for you? Like what's the final result you excepted. |
I would like mypy to report that Something like that:
This is evidenced in the example by the fact that |
Overload specification does not require any function body checks against overloaded signatures. Overloads are explicitly external to the function itself: foreign callers see them and don't see the implementation signature, while the impl itself is only checked against its own signature. |
For reference, PEP 484 says:
(emphasis mine) I must say I find this underwhelming. |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
When one of the alternatives of an overload has a return type T which is a subtype of the return type of the annotation U but that the body of the function returns a type V which is a subtype of U but not T, no error is reported
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=83c5a353e087d8bbe03d542e7340b4b5
Expected Behavior
mypy should complain that the body of the function returns an str which is incompatible with type bool (overload 2)
More generally, for each overload signature, mypy should check that the body of the function typechecks with the overload signature.
Actual Behavior
mypy reports no error
The text was updated successfully, but these errors were encountered: