Skip to content

Commit 4581501

Browse files
use ParamSpec for @contextmanager (#5476)
1 parent b65fa0e commit 4581501

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/contextlib.pyi

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from typing import (
1414
TypeVar,
1515
overload,
1616
)
17-
from typing_extensions import Protocol
17+
from typing_extensions import ParamSpec, Protocol
1818

1919
AbstractContextManager = ContextManager
2020
if sys.version_info >= (3, 7):
@@ -24,17 +24,19 @@ _T = TypeVar("_T")
2424
_T_co = TypeVar("_T_co", covariant=True)
2525
_T_io = TypeVar("_T_io", bound=Optional[IO[str]])
2626
_F = TypeVar("_F", bound=Callable[..., Any])
27+
_P = ParamSpec("_P")
2728

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

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

34-
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ...
35+
# type ignore to deal with incomplete ParamSpec support in mypy
36+
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore
3537

3638
if sys.version_info >= (3, 7):
37-
def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ...
39+
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore
3840

3941
class _SupportsClose(Protocol):
4042
def close(self) -> None: ...

0 commit comments

Comments
 (0)