-
-
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
Regression with type narrowing of bool #11839
Comments
Ok, looks like I was able to debug this problem. It is not really related to #10389, but this PR just made this problem visible. But, theoretically you can come up with other examples. Like: from typing import Any
var: Any
reveal_type(var) # N: Revealed type is "Any"
assert isinstance(var, bool) or isinstance(var, str)
reveal_type(var) # N: Revealed type is "Union[builtins.bool, builtins.str]"
if isinstance(var, bool):
reveal_type(var) # N: Revealed type is "builtins.bool"
# Should be `Union[builtins.bool, builtins.str]`, but:
reveal_type(var) # N: Revealed type is "Any" What is the cause of this problem? Lines 232 to 237 in f96446c
I guess we should write proper type joiner for |
I have a related issue. Not sure if the same cause, though. In this code:
In mypy 0.910 everything was fine. In pyright everything is also correctly inferred. |
Regression in
0.920
/0.930
compared with0.910
.The type should not be lost if it can't be narrowed to
Literal[True]
orLiteral[False]
. It's a side effect of #10389. The issue was already mentioned #10389 (comment) but hasn't been addressed yet./CC: @ethan-leba
The text was updated successfully, but these errors were encountered: