Bug Report
mypy --warn-unreachable will error on an unreachable return after an if block but not a semantically equivalent else: return ... after an if block. This shows up in platform checking logic, as an example of "unreachable code" which mypy understands and allows.
Based on what I found in existing warn-unreachable issues, there's no report of this same issue.
To Reproduce
Run mypy --warn-unreachable on the two following samples.
This passes:
def foo():
if sys.platform != "win32":
return 1
else:
return 0
This fails (on Linux/macOS. Use == "win32" to observe on Windows):
def foo():
if sys.platform != "win32":
return 1
return 0
I also put together a small example dir of this in a github repo, if that makes it easier:
https://github.com/sirosen/repro/tree/2a56d3b/mypy-issues
Expected Behavior
mypy should pass on both of these, as they are the same.
Your Environment
Bug Report
mypy --warn-unreachablewill error on an unreachablereturnafter anifblock but not a semantically equivalentelse: return ...after anifblock. This shows up in platform checking logic, as an example of "unreachable code" which mypy understands and allows.Based on what I found in existing warn-unreachable issues, there's no report of this same issue.
To Reproduce
Run
mypy --warn-unreachableon the two following samples.This passes:
This fails (on Linux/macOS. Use
== "win32"to observe on Windows):I also put together a small example dir of this in a github repo, if that makes it easier:
https://github.com/sirosen/repro/tree/2a56d3b/mypy-issues
Expected Behavior
mypy should pass on both of these, as they are the same.
Your Environment