You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mypy Self Checking Should Enable --warn-unreachable #18079
I tried this in the past and found that it caused too many false-positive errors in the self-check at that point to make it feasible. For example, branches under if sys.platform == "win32" tests were thought to be unreachable if checking with --platform=linux (strictly speaking that's true, but it's very annoying and not at all useful to have that cause the check to fail).
The reachability heuristics mypy uses may have improved since then, though; it was a while ago that I tried it.
For example, branches under if sys.platform == "win32" tests were thought to be unreachable if checking with --platform=linux
I don't think this is the case anymore. I also haven't had any problems with it in my personal projects and going randomly through 8 of the 39 issues raised above, Mypy seems to be correct about all of them except maybe one that is related to mypy_extensions.trait. I'm not sure I have the time right now, but I really believe that this would be worth it.
I absolutely agree that this would be worth it if it is possible! I wasn't trying to dissuade anybody, was just giving context on something I previously tried a while back :-)
And, it may well be that the check has improved significantly since I tried it last!
I started doing this (as a blocker for another mypy change) and the first 3 errors I had to fix were just #10773... So I think that blocks this. Things like this:
defparse_gray_color(cup: bytes) ->str:
"""Reproduce a gray color in ANSI escape sequence"""ifsys.platform=="win32":
assertFalse, "curses is not available on Windows"set_color="".join([cup[:-1].decode(), "m"]) # E: Statement is unreachablegray=curses.tparm(set_color.encode("utf-8"), 1, 9).decode()
returngray
(obviously this can be made reachable (use assert sys.platform != "win32", "curses is not available on Windows") but IMO it's better to avoid that churn)
Nevermind I got confused when thinking about this issue so I'd rather just update these functions that think more.
Activity
sobolevn commentedon Oct 31, 2024
Please, feel free to send a PR.
AlexWaygood commentedon Nov 1, 2024
I tried this in the past and found that it caused too many false-positive errors in the self-check at that point to make it feasible. For example, branches under
if sys.platform == "win32"tests were thought to be unreachable if checking with--platform=linux(strictly speaking that's true, but it's very annoying and not at all useful to have that cause the check to fail).The reachability heuristics mypy uses may have improved since then, though; it was a while ago that I tried it.
davidhalter commentedon Nov 1, 2024
I don't think this is the case anymore. I also haven't had any problems with it in my personal projects and going randomly through 8 of the 39 issues raised above, Mypy seems to be correct about all of them except maybe one that is related to
mypy_extensions.trait. I'm not sure I have the time right now, but I really believe that this would be worth it.JelleZijlstra commentedon Nov 1, 2024
I think turning this option on for mypy itself would be a good way to dogfood it and force ourselves to make sure it is reliable.
AlexWaygood commentedon Nov 1, 2024
I absolutely agree that this would be worth it if it is possible! I wasn't trying to dissuade anybody, was just giving context on something I previously tried a while back :-)
And, it may well be that the check has improved significantly since I tried it last!
A5rocks commentedon Jan 24, 2025
I started doing this (as a blocker for another mypy change) and the first 3 errors I had to fix were just #10773... So I think that blocks this. Things like this:
(obviously this can be made reachable (use
assert sys.platform != "win32", "curses is not available on Windows") but IMO it's better to avoid that churn)Nevermind I got confused when thinking about this issue so I'd rather just update these functions that think more.
Enable `warn_unreachable` for `mypy` self-check (#18523)
Enable `warn_unreachable` for `mypy` self-check (python#18523)