Python type hints and context managers : <p>How should a context manager be annotated with Python type hints?</p>

<pre><code>import typing

@contextlib.contextmanager
def foo() -&gt; ???:
    yield
</code></pre>

<p>The <a href="https://docs.python.org/3.8/library/contextlib.html" rel="noreferrer">documentation on contextlib</a> doesn't mention types much.</p>

<p>The <a href="https://docs.python.org/3.6/library/typing.html#typing.ContextManager" rel="noreferrer">documentation on typing.ContextManager</a> is not all that helpful either.</p>

<p>There's also <a href="https://docs.python.org/3.8/library/typing.html#typing.Generator" rel="noreferrer">typing.Generator</a>, which at least has an example. Does that mean I should use <code>typing.Generator[None, None, None]</code> and not <code>typing.ContextManager</code>?</p>

<pre><code>import typing

@contextlib.contextmanager
def foo() -&gt; typing.Generator[None, None, None]:
    yield
</code></pre>
