From 089eccd5368557f457cc4d3228bb3e5908c69907 Mon Sep 17 00:00:00 2001 From: donBarbos Date: Thu, 21 Aug 2025 15:40:26 +0400 Subject: [PATCH 1/2] [stdlib] Update `_interpreters` Related #14588 * Source: https://github.com/python/cpython/blob/main/Modules/_interpretersmodule.c --- stdlib/_interpreters.pyi | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index f89a24e7d85c..8fdbc0394375 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -1,6 +1,6 @@ import types from collections.abc import Callable -from typing import Any, Final, Literal, SupportsIndex, TypeVar +from typing import Any, Final, Literal, SupportsIndex, TypeVar, overload from typing_extensions import TypeAlias _R = TypeVar("_R") @@ -18,42 +18,38 @@ class CrossInterpreterBufferView: def new_config(name: _Configs = "isolated", /, **overides: object) -> types.SimpleNamespace: ... def create(config: types.SimpleNamespace | _Configs | None = "isolated", *, reqrefs: bool = False) -> int: ... def destroy(id: SupportsIndex, *, restrict: bool = False) -> None: ... -def list_all(*, require_ready: bool) -> list[tuple[int, int]]: ... -def get_current() -> tuple[int, int]: ... -def get_main() -> tuple[int, int]: ... +def list_all(*, require_ready: bool = False) -> list[tuple[int, _Whence]]: ... +def get_current() -> tuple[int, _Whence]: ... +def get_main() -> tuple[int, _Whence]: ... def is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ... def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ... def whence(id: SupportsIndex) -> _Whence: ... def exec( - id: SupportsIndex, - code: str | types.CodeType | Callable[[], object], - shared: _SharedDict | None = None, - *, - restrict: bool = False, + id: SupportsIndex, code: str | types.CodeType | Callable[[], object], shared: _SharedDict = {}, *, restrict: bool = False ) -> None | types.SimpleNamespace: ... def call( id: SupportsIndex, callable: Callable[..., _R], - args: tuple[Any, ...] | None = None, - kwargs: dict[str, Any] | None = None, + args: tuple[Any, ...] = (), + kwargs: dict[str, Any] = {}, *, + preserve_exc: bool = False, restrict: bool = False, ) -> tuple[_R, types.SimpleNamespace]: ... def run_string( - id: SupportsIndex, - script: str | types.CodeType | Callable[[], object], - shared: _SharedDict | None = None, - *, - restrict: bool = False, + id: SupportsIndex, script: str | types.CodeType | Callable[[], object], shared: _SharedDict = {}, *, restrict: bool = False ) -> None: ... def run_func( - id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: _SharedDict | None = None, *, restrict: bool = False + id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: _SharedDict = {}, *, restrict: bool = False ) -> None: ... def set___main___attrs(id: SupportsIndex, updates: _SharedDict, *, restrict: bool = False) -> None: ... def incref(id: SupportsIndex, *, implieslink: bool = False, restrict: bool = False) -> None: ... def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ... def is_shareable(obj: object) -> bool: ... -def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace: ... +@overload +def capture_exception(exc: BaseException) -> types.SimpleNamespace: ... +@overload +def capture_exception(exc: None = None) -> None: ... _Whence: TypeAlias = Literal[0, 1, 2, 3, 4, 5] WHENCE_UNKNOWN: Final = 0 From 57d9027974426ad062fbb3e0ab992a350f5edf68 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Thu, 21 Aug 2025 14:01:17 +0000 Subject: [PATCH 2/2] Update _interpreters.pyi Co-authored-by: Jelle Zijlstra --- stdlib/_interpreters.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 8fdbc0394375..2c604b30f5aa 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -49,7 +49,7 @@ def is_shareable(obj: object) -> bool: ... @overload def capture_exception(exc: BaseException) -> types.SimpleNamespace: ... @overload -def capture_exception(exc: None = None) -> None: ... +def capture_exception(exc: None = None) -> types.SimpleNamespace | None: ... _Whence: TypeAlias = Literal[0, 1, 2, 3, 4, 5] WHENCE_UNKNOWN: Final = 0