-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type of conditional expression is object #8074
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
Alternatively, inferring Inferring a union type would break backward compatibility. If the fallout is not too bad, it may still make sense. |
Note that a good fix for #4975 may automatically lead to inferring |
Here is a simpler reproduction:
|
This issue is addressed in PR #8335. |
I am also facing a similar problem.
Mypy shows this error message:
|
@carlosporta That's a separate issue. Mypy tries to find the common base class of |
@intgr, I understood what is happening, but this only happens using when using a conditional expression. If I change it to a conditional statement mypy identifies the shape protocol correctly as the return type.< 8000 /p> This works perfectly, no error messages on mypy:
Should I create a new issue (Type of conditional expression is object) or am I facing something similar to this issue? |
@carlosporta I suspect an issue already exists for that, not totally sure. If you don't find one, feel free to open a new one. But there's a historical background to why the ternary condition works as it does, I believe there's no easy fix: #3487 #5095 |
I'm still seeing this issue on repro: from typing import Tuple, List, cast
x: List[Tuple[str, str]] = [("a", "b"), ("c", "d")]
c1, c2 = zip(*x) if len(x) > 0 else ([], [])
|
@hsghori Please do not report bugs as comments on old bugs, unless you're absolutely certain it's the exact same root cause. And when reporting bugs, ensure that your bug is reproducible in the latest git version, or at least latest release version, of the project. I cannot reproduce this issue with mypy 0.931
|
The type of the following conditional expression is
object
:It should be a union type instead, such as
Union[List[str], Tuple[str, str]]
.(Note that
str.split
returnsList[str]
while theelse
branch has the typeTuple[str, str]
.)This is a follow-up to #3487.
The text was updated successfully, but these errors were encountered: