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
Given a block dependent on if MYPY, if it always returns, mypy will conclude that everything following is unreachable. This shouldn't be obviously different to using an else block.
To Reproduce
from typing import Any, cast
MYPY = False
def foo(p):
# type: (Any) -> int
doc = p
if MYPY:
return cast(int, doc)
else:
# needs to be in else for MYPY to believe this is reachable
return doc
def bar(p):
# type: (Any) -> int
doc = p
if MYPY:
return cast(int, doc)
return doc
Expected Behavior
Either both output [unreachable] or both type check successfully.
Actual Behavior
foo.py:19: error: Statement is unreachable [unreachable]
i.e.: only bar fails to typecheck
Your Environment
Mypy version used: 0.910
Mypy command-line flags: --warn-unreachable
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10.0
Operating system and version: Arch Linux
The text was updated successfully, but these errors were encountered:
Bug Report
Given a block dependent on
if MYPY
, if it always returns, mypy will conclude that everything following is unreachable. This shouldn't be obviously different to using anelse
block.To Reproduce
Expected Behavior
Either both output
[unreachable]
or both type check successfully.Actual Behavior
i.e.: only
bar
fails to typecheckYour Environment
--warn-unreachable
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: