mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Make ExitStack, AbstractContextManager and AsyncAbstractContextManager generic in return type of __exit__ (#11048)
This commit is contained in:
@@ -129,9 +129,6 @@ if sys.version_info >= (3, 11):
|
||||
if sys.version_info >= (3, 12):
|
||||
__all__ += ["TypeAliasType", "override"]
|
||||
|
||||
ContextManager = AbstractContextManager
|
||||
AsyncContextManager = AbstractAsyncContextManager
|
||||
|
||||
Any = object()
|
||||
|
||||
def final(f: _T) -> _T: ...
|
||||
@@ -431,6 +428,18 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return
|
||||
@property
|
||||
def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ...
|
||||
|
||||
# NOTE: Technically we would like this to be able to accept a second parameter as well, just
|
||||
# like it's counterpart in contextlib, however `typing._SpecialGenericAlias` enforces the
|
||||
# correct number of arguments at runtime, so we would be hiding runtime errors.
|
||||
@runtime_checkable
|
||||
class ContextManager(AbstractContextManager[_T_co, bool | None], Protocol[_T_co]): ...
|
||||
|
||||
# NOTE: Technically we would like this to be able to accept a second parameter as well, just
|
||||
# like it's counterpart in contextlib, however `typing._SpecialGenericAlias` enforces the
|
||||
# correct number of arguments at runtime, so we would be hiding runtime errors.
|
||||
@runtime_checkable
|
||||
class AsyncContextManager(AbstractAsyncContextManager[_T_co, bool | None], Protocol[_T_co]): ...
|
||||
|
||||
@runtime_checkable
|
||||
class Awaitable(Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
|
||||
Reference in New Issue
Block a user