8000 use ParamSpec for @contextmanager by JelleZijlstra · Pull Request #5476 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

use ParamSpec for @contextmanager #5476

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 3 commits into from
Jun 14, 2021
Merged
Changes from 1 commit
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
Next Next commit
use ParamSpec for @contextmanager
  • Loading branch information
JelleZijlstra committed May 16, 2021
commit e942284c34938af87cb23e6051f218e458268af7
7 changes: 4 additions & 3 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ from typing import (
TypeVar,
overload,
)
from typing_extensions import Protocol
from typing_extensions import ParamSpec, Protocol

AbstractContextManager = ContextManager
if sys.version_info >= (3, 7):
Expand All @@ -23,17 +23,18 @@ _T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_io = TypeVar("_T_io", bound=Optional[IO[str]])
_F = TypeVar("_F", bound=Callable[..., Any])
_P = ParamSpec("_P")

_ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
_CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc)

class _GeneratorContextManager(ContextManager[_T_co]):
def __call__(self, func: _F) -> _F: ...

def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ...
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ...

if sys.version_info >= (3, 7):
def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ...
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ...

class _SupportsClose(Protocol):
def close(self) -> None: ...
Expand Down
0