-
-
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
[possibly-undefined] Fix loop misconceptions #17720
base: master
Are you sure you want to change the base?
[possibly-undefined] Fix loop misconceptions #17720
Conversation
you would want to investigate |
8a921a4
to
65935c6
Compare
55bfee2
to
0a4d22c
Compare
This comment has been minimized.
This comment has been minimized.
cdb4994
to
27b2c57
Compare
This comment has been minimized.
This comment has been minimized.
don't get worried that this primer is empty, it doesn't have any rules enabled. if you wanted, you could run a custom primer with the relevant rule enabled |
27b2c57
to
730e65a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
aa021aa
to
d8689ea
Compare
This comment has been minimized.
This comment has been minimized.
d8689ea
to
082ab1b
Compare
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This PR fixes two misconceptions in the current
possibly-undefined
handling offor
andwhile
loops.for
loop: index is only defined if the body is executedCurrently, the index is always considered as defined. Counter example:
for
andwhile
loop:else
is executed if the body is not executedCurrently, the
else
block of loops is only considered as executed if there was nobreak
. Counter examples:The fix basically handles both cases like
if {body is executed}: ...; else: ...
.This is more accurate than the current implementation, but there is still room for improvement: #14209 (comment)
Refactorings
Following the Boy Scout Rule, I added a few minor code style improvements in separate commits. I'm fine with dropping them, please see them as suggestions.