Closed
Description
I am reporting what I think is a bug in mypy. I think it raises a false positive error: Missing return statement
when one has a function that is guaranteed to raise an exception (never return) while in the except clause of a try statement.
Code Sample
false_pos_no_return.py
:
def raise_exception():
raise Exception
def test() -> int:
try:
return 1
except Exception:
raise_exception()
What mypy reports:
path/to/false_pos_no_return.py: note: In function "test":
path/to/false_pos_no_return.py:5: error: Missing return statement [return]
Workarounds
One can add either of the following statements at the end of the except clause:
raise
assert False
And the error goes away: Success: no issues found in 1 source file
Expectations
My expectations are that mypy should be able to detect that raise_exception
will never actually return.
Similar Issues
#1229 seems to be similar, but it seems a decisive conclusion wasn't reached.
Versions
python==3.6.5
mypy==0.780
Metadata
Metadata
Assignees
Labels
No labels