You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ mypy test.pytest.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?
The text was updated successfully, but these errors were encountered:
Uh, I realized my workaround is wrong; using a # type: ignore only suppresses the error on that line, and mypy, not getting a type hint as in # type: Logger, moves on with the assumption that logger is logging.Logger, and declares any custom method as nonexistent:
I don't think we should fix this in typeshed. The only fix I can see is to make getLogger return Any, but I feel like that sacrifices too much type safety in the common case for a rare use case.
Feel free to reopen if you think there is a tractable fix.
Consider
test.py
:The problem here is that
logging.getLogger()
actually returns a logger of the class set previously bylogging.setLoggerClass()
, but the stub is inflexible and just assumeslogging.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?The text was updated successfully, but these errors were encountered: