contextlib.pyi ExitStack.callback take Callable (#1908)

* contextlib.pyi ExitStack.callback take Callable

The documentation for ExitStack does not specify the return type of the callable's passed to callback.  
Saying that they always return None breaks a very common use case for ExitStack, which is to "schedule" changes to a collection 
while iterating it.  

```
with ExitStack() as stack:
    for key, value in adict.items():
        if ...:
            stack.callback(adict.pop, key)
```

I also added AsyncExitStack, using Awaitable.

* Moving to Explicit Any in Generics
This commit is contained in:
Jason Fried
2018-02-24 09:41:13 -08:00
committed by Jelle Zijlstra
parent f91c891ad4
commit f5b3979b70

View File

@@ -59,8 +59,8 @@ if sys.version_info >= (3,):
def __init__(self) -> None: ...
def enter_context(self, cm: ContextManager[_T]) -> _T: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def callback(self, callback: Callable[..., None],
*args: Any, **kwds: Any) -> Callable[..., None]: ...
def callback(self, callback: Callable[..., Any],
*args: Any, **kwds: Any) -> Callable[..., Any]: ...
def pop_all(self: _U) -> _U: ...
def close(self) -> None: ...
def __enter__(self: _U) -> _U: ...
@@ -73,7 +73,7 @@ if sys.version_info >= (3, 7):
_ExitCoroFunc = Callable[[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]], Awaitable[bool]]
_CallbackCoroFunc = Callable[..., Awaitable[None]]
_CallbackCoroFunc = Callable[..., Awaitable[Any]]
_ACM_EF = TypeVar('_ACM_EF', AsyncContextManager, _ExitCoroFunc)
class AsyncExitStack(AsyncContextManager[AsyncExitStack]):
@@ -82,8 +82,8 @@ if sys.version_info >= (3, 7):
def enter_async_context(self, cm: AsyncContextManager[_T]) -> Awaitable[_T]: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
def callback(self, callback: Callable[..., None],
*args: Any, **kwds: Any) -> Callable[..., None]: ...
def callback(self, callback: Callable[..., Any],
*args: Any, **kwds: Any) -> Callable[..., Any]: ...
def push_async_callback(self, callback: _CallbackCoroFunc,
*args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
def pop_all(self: _S) -> _S: ...