-
-
Notifications
You must be signed in to change notification settings - Fork 3k
False error in conditional expression returning union #6898
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
There is a similar error when trying to return a def f(b: bool) -> Sequence[int]:
return (1,) if b else (2, 3)
|
The tuple example is a separate (relatively simple, but old) issue. The original example is just another case (among dozens) where single-bin inference would help. I think we should really do this. |
A similar problem: from typing import Union
def f(a: Union[str, int], b: Union[str, int]) -> Union[str, float]:
return a if isinstance(a, str) else b if isinstance(b, str) else a / b
|
Likely the same issue: from typing import Callable, Optional, TypeVar
T = TypeVar("T")
def f(
a: Callable[[], T],
b: Callable[[], T]
) -> T:
return a()
op: Optional[int] = f(lambda: 1, lambda: None)
Works bare |
I'm getting `Argument 1 to "func" has incompatible type "Union[str, float]"; expected "str" [arg-type]'. Is this related as well? Am I doing something wrong? |
Bug
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
a.py:12: error: Argument 1 to "get_or_str" has incompatible type "bool"; expected "str"
No error.
Do you see the same issue after installing mypy from Git master?
0.710+dev.5f08ccf029aa3046b15e1afc60743ba692e4758d (from master)
None
The text was updated successfully, but these errors were encountered: