-
-
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
(🎁) Support for
/else
statement in partially defined check
#14097
Comments
Thanks for the bug report! mypy isn't smart enough to detect that the list Do you have a real-world example where this would matter? In the toy example here it seems like it's better to just simplify everything to |
This issue isn't regarding an empty list, the
Again, this isn't regarding a list that is empty, so the body is potentially reachable.
Yes, some projects I have lit up with false positives when I updated mypy. Basically any scenario where a |
Yep! You're totally right. Thanks for pointing this out; sent a PR with the fix. |
`else` in loops is executed if the loop didn't exit via a raise, return, or a break. Therefore, we should treat it execution as unconditional if there is not a break statement. This PR also improves error messages in `else`, reporting them as "may be undefined" instead of "used before definition" Fixes #14097 Co-authored-by: Ivan Levkivskyi <[email protected]>
follow up: #14209 |
This is incorrect,
result
will always be defined in this case.The text was updated successfully, but these errors were encountered: