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
8000
Prev Previous commit
Next Next commit
Experiment with using Iterator instead of Generator
  • Loading branch information
AlexWaygood committed Dec 23, 2021
commit 52e8874916ebcc94e60b65739f6cb00d109f7ef2
24 changes: 11 additions & 13 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ if sys.version_info >= (3, 7):
_GeneratorContextManagerBase[_P], # type: ignore[misc]
AbstractContextManager[_T_co],
ContextDecorator,
Generic[_P, _T_co, _T_contra, _V],
Generic[_P, _T_co],
):
def __init__(self, func: Callable[_P, Generator[_T_co, _T_contra, _V]], args: _P.args, kwds: _P.kwds) -> None: ... # type: ignore[name-defined]
gen: Generator[_T_co, _T_contra, _V]
func: Callable[_P, Generator[_T_co, _T_contra, _V]]
def contextmanager(
func: Callable[_P, Generator[_T_co, _T_contra, _V]]
) -> Callable[_P, _GeneratorContextManager[_P, _T_co, _T_contra, _V]]: ...
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]]: ...

else:
class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator, Generic[_T_co]): ...
Expand All @@ -72,14 +70,14 @@ if sys.version_info >= (3, 10):
_GeneratorContextManagerBase[_P], # type: ignore[misc]
AbstractAsyncContextManager[_T_co],
AsyncContextDecorator,
Generic[_P, _T_co, _T_contra],
Generic[_P, _T_co],
):
def __init__(self, func: Callable[_P, AsyncGenerator[_T_co, _T_contra]], args: _P.args, kwds: _P.kwds) -> None: ... # type: ignore[name-defined]
gen: AsyncGenerator[_T_co, _T_contra]
func: Callable[_P, AsyncGenerator[_T_co, _T_contra]]
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, AsyncGenerator[_T_co, _T_contra]]
) -> Callable[_P, _AsyncGeneratorContextManager[_P, _T_co, _T_contra]]: ...
func: Callable[_P, AsyncIterator[_T_co]]
) -> Callable[_P, _AsyncGeneratorContextManager[_P, _T_co]]: ...

elif sys.version_info >= (3, 7):
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], Generic[_T_co]): ...
Expand Down
10 changes: 3 additions & 7 deletions stubs/decorator/decorator.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import sys
from typing import Any, Callable, Generator, Generic, Iterator, NamedTuple, Pattern, Text, Tuple, TypeVar
from typing import Any, Callable, Generic, Iterator, NamedTuple, Pattern, Text, Tuple, TypeVar
from typing_extensions import ParamSpec

_Func = TypeVar("_Func", bound=Callable[..., Any])
_P = ParamSpec("_P")
_T_co = TypeVar("_T_co", covariant=True)
_T_contra = TypeVar("_T_contra", contravariant=True)
_V = TypeVar("_V", covariant=True)
_T = TypeVar("_T")

def get_init(cls: type) -> None: ...
Expand Down Expand Up @@ -82,10 +80,8 @@ def decorator(

if sys.version_info >= (3, 7):
# type-ignore because mypy thinks _P is unbound (it isn't)
class ContextManager(_GeneratorContextManager[_P, _T_co, _T_contra, _V], Generic[_P, _T_co, _T_contra, _V]): ... # type: ignore[misc]
def contextmanager(
func: Callable[_P, Generator[_T_co, _T_contra, _V]]
) -> Callable[_P, ContextManager[_P, _T_co, _T_contra, _V]]: ...
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]): ...
Expand Down
0