Skip to content

Commit f69d312

Browse files
committed
make AbstractContextManager.__enter__ abstract
1 parent 4ab04d2 commit f69d312

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

stdlib/contextlib.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ _CM_EF = TypeVar("_CM_EF", bound=AbstractContextManager[Any, Any] | _ExitFunc)
4747
@runtime_checkable
4848
class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
4949
__slots__ = ()
50+
@abstractmethod # is not actually abstract, but the default implementation can't be properly accounted for in the type system
5051
def __enter__(self) -> _T_co: ...
5152
@abstractmethod
5253
def __exit__(
@@ -59,6 +60,7 @@ class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[m
5960
@runtime_checkable
6061
class AbstractAsyncContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
6162
__slots__ = ()
63+
@abstractmethod # is not actually abstract, but the default implementation can't be properly accounted for in the type system
6264
async def __aenter__(self) -> _T_co: ...
6365
@abstractmethod
6466
async def __aexit__(
@@ -82,6 +84,7 @@ class _GeneratorContextManager(
8284
AbstractContextManager[_T_co, bool | None],
8385
ContextDecorator,
8486
):
87+
def __enter__(self) -> _T_co: ...
8588
def __exit__(
8689
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
8790
) -> bool | None: ...
@@ -106,6 +109,7 @@ if sys.version_info >= (3, 10):
106109
AbstractAsyncContextManager[_T_co, bool | None],
107110
AsyncContextDecorator,
108111
):
112+
async def __aenter__(self) -> _T_co: ...
109113
async def __aexit__(
110114
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
111115
) -> bool | None: ...
@@ -134,6 +138,7 @@ _SupportsCloseT = TypeVar("_SupportsCloseT", bound=_SupportsClose)
134138

135139
class closing(AbstractContextManager[_SupportsCloseT, None]):
136140
def __init__(self, thing: _SupportsCloseT) -> None: ...
141+
def __enter__(self) -> _SupportsCloseT: ...
137142
def __exit__(self, *exc_info: Unused) -> None: ...
138143

139144
if sys.version_info >= (3, 10):
@@ -145,10 +150,12 @@ if sys.version_info >= (3, 10):
145150

146151
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT, None]):
147152
def __init__(self, thing: _SupportsAcloseT) -> None: ...
153+
async def __aenter__(self) -> _SupportsAcloseT: ...
148154
async def __aexit__(self, *exc_info: Unused) -> None: ...
149155

150156
class suppress(AbstractContextManager[None, bool]):
151157
def __init__(self, *exceptions: type[BaseException]) -> None: ...
158+
def __enter__(self) -> None: ...
152159
def __exit__(
153160
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
154161
) -> bool: ...
@@ -165,6 +172,7 @@ _SupportsRedirectT = TypeVar("_SupportsRedirectT", bound=_SupportsRedirect | Non
165172

166173
class _RedirectStream(AbstractContextManager[_SupportsRedirectT, None]):
167174
def __init__(self, new_target: _SupportsRedirectT) -> None: ...
175+
def __enter__(self) -> _SupportsRedirectT: ...
168176
def __exit__(
169177
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
170178
) -> None: ...

0 commit comments

Comments
 (0)