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.
Running mypy on the below
from typing import TypeVar
ExceptionType = TypeVar('ExceptionType', bound=BaseException)
def my_func(exception_type: ExceptionType) -> None:
try:
pass
except exception_type:
pass
results in the error:
error: Exception type must be derived from BaseException
How can I get it to pass type checking?