Request
The return type of function _get_mutex_context_from_loglevel_timeout should be AbstractContextManager[Optional[bool]], but it is annotated as Any to satisfy the linter in Python 3.7 and 3.8, as generic AbstractContextManager was introduced in Python 3.9 #18239.
Possible implementation
Once we drop support for Python 3.7 and 3.8, we can change the return type back to AbstractContextManager[Optional[bool]].