Open
Description
import contextlib
from typing import Iterator
@contextlib.contextmanager
def context_func() -> Iterator[None]:
try:
yield
except Exception:
pass
def foo() -> None:
with context_func():
raise Exception
print("xxx") # mypy: Statement is unreachable
Since context managers can silence exceptions, I don't think mypy
should consider statements after the context to be unreachable due to exceptions which might be raised within the context.
Flags needed: --warn-unreachable
.
Python 3.6, mypy 0.770, also master (at 2a3de7b)