Consider test.py:
import logging
class Logger(logging.Logger):
pass
logging.setLoggerClass(Logger)
logger = logging.getLogger(__name__) # type: Logger
$ mypy test.py
test.py:7: error: Incompatible types in assignment (expression has type "logging.Logger", variable has type "test.Logger")
The problem here is that logging.getLogger() actually returns a logger of the class set previously by logging.setLoggerClass(), but the stub is inflexible and just assumes logging.Logger.
I'm not sure how to fix this, or whether it's fixable with mypy's current feature set. I'd be happy to take this on if someone could point me in the right direction.
In the meantime, is there a better workaround than just # type: ignore the line?