Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

sobolevn
Copy link
Member

This check prooved to be useful, since it find a lot of dead / incorrect code.

Closes #18079

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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

@sobolevn
Copy link
Member Author

I think it could worth replacing some of these with asserts

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.

@A5rocks
Copy link
Collaborator

A5rocks commented Jan 24, 2025

I think it could worth replacing some of these with asserts

Do you have some specific items in mind? I can surely add asserts where needed.

I actually just did this too! I ended up with quite a few asserts so maybe that can be a second opinion. master...A5rocks:mypy:experiments/warn_unreachable (I also deferred on mypy_extensions.trait subclassing instead of updating the isinstance)


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.

Copy link
Collaborator

@A5rocks A5rocks left a 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
Copy link
Collaborator

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.

Copy link
Member Author

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).

Copy link
Member Author

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.

Copy link
Collaborator

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).

Huh I was able to. But I guess that might just be because I was testing on Windows.

Copy link
Member Author

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.

mypy/util.py Show resolved Hide resolved
mypy_self_check.ini Show resolved Hide resolved
mypy/test/testmerge.py Show resolved Hide resolved
mypy/test/data.py Show resolved Hide resolved
mypy/server/astdiff.py Show resolved Hide resolved
@sobolevn
Copy link
Member Author

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?

Sorry, I don't understand your question. Can you please provide an example?

mypy/nodes.py Outdated Show resolved Hide resolved

This comment has been minimized.

@A5rocks
Copy link
Collaborator

A5rocks commented Jan 25, 2025

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?

Sorry, I don't understand your question. Can you please provide an example?

I was confused, actually. I've now read the docstring of FuncBase and I get why you switched out the isinstance checks... Except it refers to an issue that's closed! You're just doing #13607 (comment) (3), which will mean we have to revert a bunch of lines whenever we actually fix the issue (1).

IMO we should fix the issue at hand but continuing with (3) is OK as long as you update the comment around SYMBOL_FUNCBASE_TYPES (and maybe put a TODO or something there?).

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sobolevn
Copy link
Member Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mypy Self Checking Should Enable --warn-unreachable
4 participants