@@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
55from collections .abc import AsyncGenerator , AsyncIterator , Awaitable , Callable , Generator , Iterator
66from types import TracebackType
77from typing import Any , Generic , Protocol , TypeVar , overload , runtime_checkable , type_check_only
8- from typing_extensions import ParamSpec , Self , TypeAlias
8+ from typing_extensions import ParamSpec , Self , TypeAlias , deprecated
99
1010__all__ = [
1111 "contextmanager" ,
@@ -86,6 +86,12 @@ class _GeneratorContextManager(
8686 self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
8787 ) -> bool | None : ...
8888
89+ @overload
90+ def contextmanager (func : Callable [_P , Generator [_T_co , None , object ]]) -> Callable [_P , _GeneratorContextManager [_T_co ]]: ...
91+ @overload
92+ @deprecated (
93+ "Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead."
94+ )
8995def contextmanager (func : Callable [_P , Iterator [_T_co ]]) -> Callable [_P , _GeneratorContextManager [_T_co ]]: ...
9096
9197if sys .version_info >= (3 , 10 ):
@@ -112,6 +118,13 @@ else:
112118 self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
113119 ) -> bool | None : ...
114120
121+ @overload
122+ def asynccontextmanager (func : Callable [_P , AsyncGenerator [_T_co ]]) -> Callable [_P , _AsyncGeneratorContextManager [_T_co ]]: ...
123+ @overload
124+ @deprecated (
125+ "Annotating the return type as `-> AsyncIterator[Foo]` with `@asynccontextmanager` is deprecated. "
126+ "Use `-> AsyncGenerator[Foo]` instead."
127+ )
115128def asynccontextmanager (func : Callable [_P , AsyncIterator [_T_co ]]) -> Callable [_P , _AsyncGeneratorContextManager [_T_co ]]: ...
116129@type_check_only
117130class _SupportsClose (Protocol ):
0 commit comments