@@ -165,9 +165,15 @@ class _BaseExitStack(Generic[_ExitT_co]):
165165 def callback (self , callback : Callable [_P , _T ], / , * args : _P .args , ** kwds : _P .kwargs ) -> Callable [_P , _T ]: ...
166166 def pop_all (self ) -> Self : ...
167167
168- # In reality this is a subclass of `AbstractContextManager`;
169- # see #7961 for why we don't do that in the stub
170- class ExitStack (_BaseExitStack [_ExitT_co ], metaclass = abc .ABCMeta ):
168+ # this class is to avoid putting `metaclass=abc.ABCMeta` on the implementations directly, as this would make them
169+ # appear explicitly abstract to some tools. this is due to the implementations not subclassing `AbstractContextManager`
170+ # see note on the subclasses
171+ @type_check_only
172+ class _BaseExitStackAbstract (_BaseExitStack [_ExitT_co ], metaclass = abc .ABCMeta ): ...
173+
174+ # In reality this is a subclass of `AbstractContextManager`, but we can't provide `Self` as the argument for `__enter__`
175+ # https://discuss.python.org/t/self-as-typevar-default/90939
176+ class ExitStack (_BaseExitStackAbstract [_ExitT_co ]):
171177 def close (self ) -> None : ...
172178 def __enter__ (self ) -> Self : ...
173179 def __exit__ (
@@ -179,9 +185,9 @@ _ExitCoroFunc: TypeAlias = Callable[
179185]
180186_ACM_EF = TypeVar ("_ACM_EF" , bound = AbstractAsyncContextManager [Any , Any ] | _ExitCoroFunc )
181187
182- # In reality this is a subclass of `AbstractAsyncContextManager`;
183- # see #7961 for why we don't do that in the stub
184- class AsyncExitStack (_BaseExitStack [_ExitT_co ], metaclass = abc . ABCMeta ):
188+ # In reality this is a subclass of `AbstractContextManager`, but we can't provide `Self` as the argument for `__enter__`
189+ # https://discuss.python.org/t/self-as-typevar-default/90939
190+ class AsyncExitStack (_BaseExitStackAbstract [_ExitT_co ]):
185191 async def enter_async_context (self , cm : AbstractAsyncContextManager [_T , _ExitT_co ]) -> _T : ...
186192 def push_async_exit (self , exit : _ACM_EF ) -> _ACM_EF : ...
187193 def push_async_callback (
0 commit comments