Fix signature of nested() -- it actually returns a list of values.

To be on the conservative side I'm making it an Iterable of values;
this should be good enough for common usages.

The types of the values actually correspond to the types of the
argument ContextManagers, but a proper signature would require
variadic type variables (https://github.com/python/typing/issues/193),
which isn't worth waiting for. :-)
This commit is contained in:
Guido van Rossum
2016-08-02 12:03:58 -07:00
parent 1e1694276c
commit 53f0ed7e68

View File

@@ -1,7 +1,7 @@
# Stubs for contextlib
from typing import (
Any, Callable, Generator, IO, Iterator, Optional, Type,
Any, Callable, Generator, IO, Iterable, Iterator, Optional, Type,
Generic, TypeVar,
)
from types import TracebackType
@@ -23,7 +23,7 @@ class ContextManager(Generic[_T]):
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
if sys.version_info < (3,):
def nested(*mgr: ContextManager[Any]) -> ContextManager[None]: ...
def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...
class closing(Generic[_T], ContextManager[_T]):
def __init__(self, thing: _T) -> None: ...