Skip to content

Commit 43c3848

Browse files
committed
make ExitStack/AsyncExitStack not appear as abstract
1 parent b0401bc commit 43c3848

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/contextlib.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ class _BaseExitStack(Generic[_ExitT_co]):
178178
def callback(self, callback: Callable[_P, _T], /, *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ...
179179
def pop_all(self) -> Self: ...
180180

181+
# this class exists to avoid `ABCMeta` appearing directly on the non-abstract inheritors
182+
@type_check_only
183+
class _ExitStackBase(metaclass=abc.ABCMeta): ...
184+
181185
# In reality this is a subclass of `AbstractContextManager`;
182186
# see #7961 for why we don't do that in the stub
183-
class ExitStack(_BaseExitStack[_ExitT_co], metaclass=abc.ABCMeta):
187+
class ExitStack(_ExitStackBase, _BaseExitStack[_ExitT_co]):
184188
def close(self) -> None: ...
185189
def __enter__(self) -> Self: ...
186190
def __exit__(
@@ -194,7 +198,7 @@ _ACM_EF = TypeVar("_ACM_EF", bound=AbstractAsyncContextManager[Any, Any] | _Exit
194198

195199
# In reality this is a subclass of `AbstractAsyncContextManager`;
196200
# see #7961 for why we don't do that in the stub
197-
class AsyncExitStack(_BaseExitStack[_ExitT_co], metaclass=abc.ABCMeta):
201+
class AsyncExitStack(_ExitStackBase, _BaseExitStack[_ExitT_co]):
198202
async def enter_async_context(self, cm: AbstractAsyncContextManager[_T, _ExitT_co]) -> _T: ...
199203
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
200204
def push_async_callback(

0 commit comments

Comments
 (0)