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
Per the Python docs, AbstractContextManager provides a default __enter__ implementation which just returns self. But this does not appear to be properly type annotated (using Self):
This is due to the duality of AbstractContextManager being both an ABC and a protocol. As a protocol it makes sense that it is generic over the return type of __enter__. Ideally we'd give the type variable a default of Self, but I'm not sure that that's possible.
Per the Python docs,
AbstractContextManager
provides a default__enter__
implementation which just returnsself
. But this does not appear to be properly type annotated (usingSelf
):Running this with
mypy
, only the second case properly reveals the type asB2
. The first one just saysAny
.At runtime, the behavior of both is identical.
I have recreated this on both Python 3.12 and Python 3.13.
The text was updated successfully, but these errors were encountered: