diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index a9ef5e4790fd..f294f7849473 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -4,11 +4,6 @@ # Please keep sorted alphabetically -_collections_abc.AsyncGenerator.ag_await -_collections_abc.AsyncGenerator.ag_code -_collections_abc.AsyncGenerator.ag_frame -_collections_abc.AsyncGenerator.ag_running -asyncio.__all__ builtins.dict.get collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023 http.client.HTTPConnection.response_class # the actual type at runtime is abc.ABCMeta @@ -221,16 +216,6 @@ _collections_abc.AsyncIterator.__anext__ _collections_abc.ByteString _collections_abc.Callable # Typing-related weirdness - -# Coroutine and Generator properties are added programmatically -_collections_abc.Coroutine.cr_await -_collections_abc.Coroutine.cr_code -_collections_abc.Coroutine.cr_frame -_collections_abc.Coroutine.cr_running -_collections_abc.Generator.gi_code -_collections_abc.Generator.gi_frame -_collections_abc.Generator.gi_running -_collections_abc.Generator.gi_yieldfrom _collections_abc.Mapping.get # Adding None to the Union messed up mypy _collections_abc.Sequence.index # Supporting None in end is not mandatory diff --git a/stdlib/@tests/stubtest_allowlists/py38.txt b/stdlib/@tests/stubtest_allowlists/py38.txt index e28a38d43f92..15c6ce1f0b3d 100644 --- a/stdlib/@tests/stubtest_allowlists/py38.txt +++ b/stdlib/@tests/stubtest_allowlists/py38.txt @@ -59,22 +59,10 @@ tkinter.tix.wantobjects builtins.input # Incorrect default value in text signature, fixed in 3.10 collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 -collections.AsyncGenerator.ag_await -collections.AsyncGenerator.ag_code -collections.AsyncGenerator.ag_frame -collections.AsyncGenerator.ag_running collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.ByteString # see comments in py3_common.txt collections.Callable -collections.Coroutine.cr_await -collections.Coroutine.cr_code -collections.Coroutine.cr_frame -collections.Coroutine.cr_running -collections.Generator.gi_code -collections.Generator.gi_frame -collections.Generator.gi_running -collections.Generator.gi_yieldfrom collections.Mapping.get # Adding None to the Union messed up mypy collections.Sequence.index # Supporting None in end is not mandatory xxsubtype # module missing from the stubs diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index 4dc61940d224..d36dd74021ed 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -50,22 +50,10 @@ typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs builtins.input # Incorrect default value in text signature, fixed in 3.10 collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 -collections.AsyncGenerator.ag_await -collections.AsyncGenerator.ag_code -collections.AsyncGenerator.ag_frame -collections.AsyncGenerator.ag_running collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.ByteString # see comments in py3_common.txt collections.Callable -collections.Coroutine.cr_await -collections.Coroutine.cr_code -collections.Coroutine.cr_frame -collections.Coroutine.cr_running -collections.Generator.gi_code -collections.Generator.gi_frame -collections.Generator.gi_running -collections.Generator.gi_yieldfrom collections.Mapping.get # Adding None to the Union messed up mypy collections.Sequence.index # Supporting None in end is not mandatory xxsubtype # module missing from the stubs @@ -141,7 +129,6 @@ tkinter.tix.Shell tkinter.tix.TclVersion tkinter.tix.TkVersion - # ============================================================ # Allowlist entries that cannot or should not be fixed; >= 3.9 # ============================================================ diff --git a/stdlib/types.pyi b/stdlib/types.pyi index fdd484c66b4f..b294a0b2f8f7 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -374,6 +374,12 @@ _ReturnT_co = TypeVar("_ReturnT_co", covariant=True) @final class GeneratorType(Generator[_YieldT_co, _SendT_contra, _ReturnT_co]): + @property + def gi_code(self) -> CodeType: ... + @property + def gi_frame(self) -> FrameType: ... + @property + def gi_running(self) -> bool: ... @property def gi_yieldfrom(self) -> GeneratorType[_YieldT_co, _SendT_contra, Any] | None: ... if sys.version_info >= (3, 11): @@ -397,6 +403,12 @@ class GeneratorType(Generator[_YieldT_co, _SendT_contra, _ReturnT_co]): class AsyncGeneratorType(AsyncGenerator[_YieldT_co, _SendT_contra]): @property def ag_await(self) -> Awaitable[Any] | None: ... + @property + def ag_code(self) -> CodeType: ... + @property + def ag_frame(self) -> FrameType: ... + @property + def ag_running(self) -> bool: ... __name__: str __qualname__: str if sys.version_info >= (3, 12): @@ -421,6 +433,14 @@ class CoroutineType(Coroutine[_YieldT_co, _SendT_contra, _ReturnT_co]): __name__: str __qualname__: str @property + def cr_await(self) -> Any | None: ... + @property + def cr_code(self) -> CodeType: ... + @property + def cr_frame(self) -> FrameType: ... + @property + def cr_running(self) -> bool: ... + @property def cr_origin(self) -> tuple[tuple[str, int, str], ...] | None: ... if sys.version_info >= (3, 11): @property diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index cde626ed1022..7c1b171a730b 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -12,7 +12,6 @@ from re import Match as Match, Pattern as Pattern from types import ( BuiltinFunctionType, CodeType, - FrameType, FunctionType, MethodDescriptorType, MethodType, @@ -473,7 +472,8 @@ _YieldT_co = TypeVar("_YieldT_co", covariant=True) _SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None) _ReturnT_co = TypeVar("_ReturnT_co", covariant=True, default=None) -class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]): +@runtime_checkable +class Generator(Iterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra, _ReturnT_co]): def __next__(self) -> _YieldT_co: ... @abstractmethod def send(self, value: _SendT_contra, /) -> _YieldT_co: ... @@ -491,14 +491,6 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return def close(self) -> None: ... def __iter__(self) -> Generator[_YieldT_co, _SendT_contra, _ReturnT_co]: ... - @property - def gi_code(self) -> CodeType: ... - @property - def gi_frame(self) -> FrameType: ... - @property - def gi_running(self) -> bool: ... - @property - def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ... # NOTE: Prior to Python 3.13 these aliases are lacking the second _ExitT_co parameter if sys.version_info >= (3, 13): @@ -524,14 +516,7 @@ _ReturnT_co_nd = TypeVar("_ReturnT_co_nd", covariant=True) class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]): __name__: str __qualname__: str - @property - def cr_await(self) -> Any | None: ... - @property - def cr_code(self) -> CodeType: ... - @property - def cr_frame(self) -> FrameType | None: ... - @property - def cr_running(self) -> bool: ... + @abstractmethod def send(self, value: _SendT_contra_nd, /) -> _YieldT_co: ... @overload @@ -566,7 +551,8 @@ class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]): def __anext__(self) -> Awaitable[_T_co]: ... def __aiter__(self) -> AsyncIterator[_T_co]: ... -class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra]): +@runtime_checkable +class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra]): def __anext__(self) -> Coroutine[Any, Any, _YieldT_co]: ... @abstractmethod def asend(self, value: _SendT_contra, /) -> Coroutine[Any, Any, _YieldT_co]: ... @@ -581,14 +567,6 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contr self, typ: BaseException, val: None = None, tb: TracebackType | None = None, / ) -> Coroutine[Any, Any, _YieldT_co]: ... def aclose(self) -> Coroutine[Any, Any, None]: ... - @property - def ag_await(self) -> Any: ... - @property - def ag_code(self) -> CodeType: ... - @property - def ag_frame(self) -> FrameType: ... - @property - def ag_running(self) -> bool: ... @runtime_checkable class Container(Protocol[_T_co]):