-
-
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
Enable warn_unreachable
for mypy
self-check
#18523
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
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.
Awesome. I think it could worth replacing some of these with asserts, just in case there's something mypy has got wrong
Do you have some specific items in mind? I can surely add asserts where needed. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I actually just did this too! I ended up with quite a few Though that branch also passes mypy's test suite, so maybe that's a sign that actually those asserts aren't necessary at all and mypy was correct. |
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'm generally unsure about the isinstance(x, FuncBase)
changes where x: Node
(and similar mypy_extensions.trait
workarounds) because it seems like that just uses tuples to work around reachability? I haven't tried some testcases locally so I'm not entirely sure though.
assert sys.platform == "win32" | ||
if sys.platform == "win32": | ||
assert sys.platform == "win32", "Running not on Windows" | ||
if sys.platform == "win32": # needed to find win specific sys apis |
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.
You can un-indent this.
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.
Nope, sadly I can't :(
Looks like that mypy does not narrow sys.platform
after assert
(this might be a bug).
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.
But, I added assert False
in the end instead, it is more readable now.
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.
Nope, sadly I can't :( Looks like that mypy does not narrow
sys.platform
afterassert
(this might be a bug).
Huh I was able to. But I guess that might just be because I was testing on Windows.
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.
Yes, you need to set platform = win32
or platform = linux
manually in .ini
file for that.
Sorry, I don't understand your question. Can you please provide an example? |
This comment has been minimized.
This comment has been minimized.
I was confused, actually. I've now read the docstring of IMO we should fix the issue at hand but continuing with (3) is OK as long as you update the comment around |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
I will leave this open for a couple of days to give an opportunity for second rounds of reviewes, and merge on Wen or so :) Thanks, @A5rocks! |
This check prooved to be useful, since it find a lot of dead / incorrect code.
Closes #18079