-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Overloaded functions fail when checked with --disallow-untyped-defs #3360
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
This is actually expected, although somewhat unintuitive. The reason is following: currently mypy does not check the body of the function against all overloads (this is very difficult in a general case involving @overload
def test(val: int) -> int: ...
@overload
def test(val: str) -> str: ...
def test(val: Union[int, str]) -> Union[int, str]:
return val I just checked the documentation, and I think this is not well documented. Would you like to make a PR? As a side comment, it is not necessary to use overloads for such simple signatures, you can just write: T = TypeVar('T', int, str)
def test(val: T) -> T:
return val |
Yeah, that was just the smallest example I could get to fail. |
For this minimal example
with --disallow-untyped-defs mypy fails with
error: Function is missing a type annotation
but without it it succeeds.
The text was updated successfully, but these errors were encountered: