title: Dynamic exception type checking
body: <p>I'm trying to specify types on some code that catches exceptions, but the exact type of exception is dynamic, i.e. specified at runtime.</p>
  <p>Running mypy on the below</p>
  <pre class="lang-py prettyprint-override"><code>from typing import TypeVar
  
  ExceptionType = TypeVar('ExceptionType', bound=BaseException)
  def my_func(exception_type: ExceptionType) -&gt; None:
      try:
          pass
      except exception_type:
          pass
  </code></pre>
  <p>results in the error:</p>
  <pre><code>error: Exception type must be derived from BaseException
  </code></pre>
  <p>How can I get it to pass type checking?</p>