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
{{ message }}
Repository navigation
LoggerAdapter is typed as a generic but using it as such raises an error at runtime #7855
mypy raises the following type-arg error : error: Missing type parameters for generic type "LoggerAdapter"
According to this type stub it's typed as a generic and should be passed the type of the logger it's an adapter for. However, changing the code into this:
makes mypy happy but raises an error at runtime: TypeError: 'type' object is not subscriptable
I'm not sure if this is an issue with the stubs or with mypy (and I'm not fully sure how they interact), so apologies if this issue should have been created on https://github.com/python/mypy instead (feel free to transfer it there if that's the case).
Activity
AlexWaygood commentedon May 17, 2022
You created the issue in the right place :) and, this is a problem we're aware of.
LoggerAdapterwill actually be generic at runtime on 3.11, because of this very issue: python/cpython#92129In the meantime, however, @Akuli's advice here is probably the best way around this issue: #5954 (comment):
There's also some great mypy docs on this problem here: https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime
babolivier commentedon May 17, 2022
That makes sense, thanks a lot for the details and references :)
fix: 3.10 logging.LoggerAdapter not subscriptable