From 31dca1d660937e2e3fe4670934b8c331d6f4144c Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 3 Jul 2023 15:54:19 +0300 Subject: [PATCH] Update `inspect` for Python3.12 (#10398) --- stdlib/inspect.pyi | 27 +++++++++++++++++++++++++++ tests/stubtest_allowlists/py312.txt | 8 -------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 2b07200f18ae..9af4c39bae9e 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -128,8 +128,21 @@ if sys.version_info >= (3, 11): "walktree", ] + if sys.version_info >= (3, 12): + __all__ += [ + "markcoroutinefunction", + "AGEN_CLOSED", + "AGEN_CREATED", + "AGEN_RUNNING", + "AGEN_SUSPENDED", + "getasyncgenlocals", + "getasyncgenstate", + "BufferFlags", + ] + _P = ParamSpec("_P") _T = TypeVar("_T") +_F = TypeVar("_F", bound=Callable[..., Any]) _T_cont = TypeVar("_T_cont", contravariant=True) _V_cont = TypeVar("_V_cont", contravariant=True) @@ -184,6 +197,9 @@ def isclass(object: object) -> TypeGuard[type[Any]]: ... def ismethod(object: object) -> TypeGuard[MethodType]: ... def isfunction(object: object) -> TypeGuard[FunctionType]: ... +if sys.version_info >= (3, 12): + def markcoroutinefunction(func: _F) -> _F: ... + if sys.version_info >= (3, 8): @overload def isgeneratorfunction(obj: Callable[..., Generator[Any, Any, Any]]) -> bool: ... @@ -360,6 +376,17 @@ class _ParameterKind(enum.IntEnum): @property def description(self) -> str: ... +if sys.version_info >= (3, 12): + AGEN_CREATED: Literal["AGEN_CREATED"] + AGEN_RUNNING: Literal["AGEN_RUNNING"] + AGEN_SUSPENDED: Literal["AGEN_SUSPENDED"] + AGEN_CLOSED: Literal["AGEN_CLOSED"] + + def getasyncgenstate( + agen: AsyncGenerator[Any, Any] + ) -> Literal["AGEN_CREATED", "AGEN_RUNNING", "AGEN_SUSPENDED", "AGEN_CLOSED"]: ... + def getasyncgenlocals(agen: AsyncGeneratorType[Any, Any]) -> dict[str, Any]: ... + class Parameter: def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ... empty = _empty diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index 0676d07211a8..a51e4bfa6461 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -53,14 +53,6 @@ importlib.resources.files importlib.util.module_for_loader importlib.util.set_loader importlib.util.set_package -inspect.AGEN_CLOSED -inspect.AGEN_CREATED -inspect.AGEN_RUNNING -inspect.AGEN_SUSPENDED -inspect.__all__ -inspect.getasyncgenlocals -inspect.getasyncgenstate -inspect.markcoroutinefunction logging.Logger.getChildren logging.__all__ logging.getHandlerByName