Better stub for contextlib.contextmanager.

This commit is contained in:
Drew Haven
2016-03-16 14:54:19 -07:00
parent d4540dca2e
commit 1f86531ead
2 changed files with 16 additions and 12 deletions

View File

@@ -2,14 +2,16 @@
# NOTE: These are incomplete!
from typing import Any, TypeVar, Generic
# TODO more precise type?
def contextmanager(func: Any) -> Any: ...
from typing import Callable, Generic, Iterator, TypeVar
_T = TypeVar('_T')
class closing(Generic[_T]):
def __init__(self, thing: _T) -> None: ...
class ContextManager(Generic[_T]):
def __enter__(self) -> _T: ...
def __exit__(self, *exc_info) -> None: ...
# TODO this doesn't capture the relationship that the returned function's args are the same as func's.
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
class closing(ContextManager[_T], Generic[_T]):
def __init__(self, thing: _T) -> None: ...

View File

@@ -2,14 +2,16 @@
# NOTE: These are incomplete!
from typing import Any, TypeVar, Generic
# TODO more precise type?
def contextmanager(func: Any) -> Any: ...
from typing import Callable, Generic, Iterator, TypeVar
_T = TypeVar('_T')
class closing(Generic[_T]):
def __init__(self, thing: _T) -> None: ...
class ContextManager(Generic[_T]):
def __enter__(self) -> _T: ...
def __exit__(self, *exc_info) -> None: ...
# TODO this doesn't capture the relationship that the returned function's args are the same as func's.
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
class closing(ContextManager[_T], Generic[_T]):
def __init__(self, thing: _T) -> None: ...