8000 Add missing attributes to `contextlib._(Async)GeneratorContextManager` by AlexWaygood · Pull Request #6676 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Add missing attributes to contextlib._(Async)GeneratorContextManager #6676

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 20 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Use ParamSpec less
  • Loading branch information
AlexWaygood committed Dec 23, 2021
commit 8d1813b6b8db4913f5f2fbd17cc347e9957ff99a
30 changes: 10 additions & 20 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,17 @@ class ContextDecorator:
def __call__(self, func: _F) -> _F: ...

if sys.version_info >= (3, 7):
class _GeneratorContextManagerBase(Generic[_P]):
class _GeneratorContextManagerBase:
def __init__(self, func: Callable[_P, Any], args: _P.args, kwds: _P.kwds) -> None: ... # type: ignore[name-defined]
gen: Any
func: Callable[_P, Any]
args: _P.args # type: ignore[name-defined]
kwds: _P.kwds # type: ignore[name-defined]
class _GeneratorContextManager(
_GeneratorContextManagerBase[_P], # type: ignore[misc]
AbstractContextManager[_T_co],
ContextDecorator,
Generic[_P, _T_co],
):
func: Callable[..., Any]
args: tuple[Any, ...]
kwds: dict[str, Any]
class _GeneratorContextManager(_GeneratorContextManagerBase, AbstractContextManager[_T_co], ContextDecorator, Generic[_T_co]):
def __init__(self, func: Callable[_P, Iterator[_T_co]], args: _P.args, kwds: _P.kwds) -> None: ... # type: ignore[name-defined]
gen: Generator[_T_co, Any, Any]
func: Callable[_P, Generator[_T_co, Any, Any]]
def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_P, _T_co]]: ...
func: Callable[..., Generator[_T_co, Any, Any]]
def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ...

else:
class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator, Generic[_T_co]): ...
Expand All @@ -65,17 +60,12 @@ if sys.version_info >= (3, 10):
class AsyncContextDecorator:
def __call__(self, func: _AF) -> _AF: ...
class _AsyncGeneratorContextManager(
_GeneratorContextManagerBase[_P], # type: ignore[misc]
AbstractAsyncContextManager[_T_co],
AsyncContextDecorator,
Generic[_P, _T_co],
_GeneratorContextManagerBase, AbstractAsyncContextManager[_T_co], AsyncContextDecorator, Generic[_T_co]
):
def __init__(self, func: Callable[_P, AsyncIterator[_T_co]], args: _P.args, kwds: _P.kwds) -> None: ... # type: ignore[name-defined]
gen: AsyncGenerator[_T_co, Any]
func: Callable[_P, AsyncGenerator[_T_co, Any]]
def asynccontextmanager(
func: Callable[_P, AsyncIterator[_T_co]]
) -> Callable[_P, _AsyncGeneratorContextManager[_P, _T_co]]: ...
func: Callable[..., AsyncGenerator[_T_co, Any]]
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ...

elif sys.version_info >= (3, 7):
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], Generic[_T_co]): ...
Expand Down
10 changes: 2 additions & 8 deletions stubs/decorator/decorator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ def decorator(
caller: Callable[..., Any], _func: Callable[..., Any] | None = ...
) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...

if sys.version_info >= (3, 7):
# type-ignore because mypy thinks _P is unbound (it isn't)
class ContextManager(_GeneratorContextManager[_P, _T_co], Generic[_P, _T_co]): ... # type: ignore[misc]
def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, ContextManager[_P, _T_co]]: ...

else:
class ContextManager(_GeneratorContextManager[_T_co], Generic[_T_co]): ...
def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, ContextManager[_T_co]]: ...
class ContextManager(_GeneratorContextManager[_T_co], Generic[_T_co]): ...

def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, ContextManager[_T_co]]: ...
def dispatch_on(*dispatch_args: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...
0