-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Consistently avoid type-checking unreachable code #15386
Consistently avoid type-checking unreachable code #15386
Conversation
0c9f506
to
1747d75
Compare
1747d75
to
517ff28
Compare
👋 @KotlinIsland and @sobolevn (re: #11361) |
Thinking about it more, it's strange that we avoid type checking those blocks. Having In this PR I'm making function and global level consistent, but how can we know it's the consistency we want? (From quickly testing in pyright, it narrows the expression to |
It's enabled by default in basedmypy. I'm sorry, I'm struggling a little to see all the differences in behavior made here. You are stating that it fixes #12409, but the output is identical. The only difference I could find is your example in the OP, although within a function, which now matches the behavior observed in master for module level. I think that is a great change. |
@KotlinIsland Sorry, you are right. I was looking for pre-existing issues and mistook #12409 to be it :) Removing the link. |
Not disagreeing with that, mind you. Rather, questioning why it should suppress type-checking: IMO that's unexpected and comes with no warning. Even if the branch is truly unreachable, suppressing all type checks until you fix reachability effectively makes it a 'blocking error', which we are trying not to have (judging by other 'blocking error' issues). |
try: | ||
# try accessing those globals that were never properly initialized | ||
import native | ||
native.test() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think native.test()
is effective in this test.
The first import native
fails, and so the second import native
also gets executed, and also fails, and we never reach native.test()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
We could explore doing things the other way round and see what the mypy_primer fallout looks like. But I'm not super optimistic, I think currently this papers over some bugs in the binder
I think it's a good idea to explore changes to this behavior, as it's not very intuitive. |
--warn-unreachable
is enabled, we'll emit an error, just once, on the first unreachable statement that's not a no-op statement. Previously a no-op statement would not have the "Unreachable statement" error, but the subsequent statements did not have the error either, e.g.