Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve contextlib #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions stdlib/2.7/contextlib.pyi

This file was deleted.

53 changes: 53 additions & 0 deletions stdlib/2and3/contextlib.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Stubs for contextlib

from typing import (
Any, Callable, Generator, IO, Optional, Type,
Generic, TypeVar,
)
from types import TracebackType
import sys

_T = TypeVar('_T')
_ExitFunc = Callable[[Optional[Type[BaseException]],
Optional[Exception],
Optional[TracebackType]], bool]
_CM_EF = TypeVar('_CM_EF', ContextManager, _ExitFunc)

# TODO already in PEP, have to get added to mypy
class ContextManager(Generic[_T]):
def __enter__(self) -> _T: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[Exception],
exc_tb: Optional[TracebackType]) -> bool: ...

def contextmanager(func: Callable[..., Generator[None, None, None]]) -> Callable[..., ContextManager[None]]: ...

if sys.version_info < (3,):
def nested(*mgr: ContextManager[Any]) -> ContextManager[None]: ...

class closing(Generic[_T], ContextManager[_T]):
def __init__(self, thing: _T) -> None: ...

if sys.version_info >= (3, 4):
class suppress(ContextManager[None]):
def __init__(self, *exceptions: Type[BaseException]) -> None: ...

class redirect_stdout(ContextManager[None]):
def __init__(self, new_target: IO[str]) -> None: ...

if sys.version_info >= (3, 5):
class redirect_stderr(ContextManager[None]):
def __init__(self, new_target: IO[str]) -> None: ...

if sys.version_info >= (3,):
class ContextDecorator:
def __call__(self, func: Callable[..., None]) -> Callable[..., ContextManager[None]]: ...

class ExitStack(ContextManager[ExitStack]):
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 pop_all(self) -> ExitStack: ...
def close(self) -> None: ...
17 changes: 0 additions & 17 deletions stdlib/3/contextlib.pyi

This file was deleted.