From 00b53ba7b0b2072d2e9e8485587731e2901fb880 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:32:09 -0400 Subject: [PATCH 01/14] Add intepreters --- stdlib/_interpeters.pyi | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 stdlib/_interpeters.pyi diff --git a/stdlib/_interpeters.pyi b/stdlib/_interpeters.pyi new file mode 100644 index 000000000000..2101b7f345cf --- /dev/null +++ b/stdlib/_interpeters.pyi @@ -0,0 +1,51 @@ +import types +from typing import Callable, Final, Literal, Mapping, SupportsIndex, final + +class InterpreterError(Exception): ... +class InterpreterNotFoundError(InterpreterError): ... +class InterpreterNotShareableError(InterpreterError): ... + +# Not-instantiable, so mark as final. +@final +class CrossInterpreterBufferView: ... + +def new_config( + name: Literal["default", "isolated", "legacy", "empty"] = "isolated", + /, + **overides: object, +) -> types.SimpleNamespace: ... +def create( + config: types.SimpleNamespace | Literal["isolated", "legacy"] | 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 is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ... +def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ... +def whence(id: SupportsIndex) -> int: ... +def exec(id: SupportsIndex, code: str, shared: bool | None = None, *, restrict: bool = False) -> None: ... +def call( + id: SupportsIndex, + callable: Callable[..., object], + args: tuple[object, ...] | None = None, + kwargs: dict[str, object] | None = None, + *, + restrict: bool = False, +) -> object: ... +def run_string(id: SupportsIndex, script: str, shared: bool | None = None, *, restrict: bool = False) -> None: ... +def run_func(id: SupportsIndex, func: Callable[..., object], shared: bool | None = None, *, restrict: bool = False) -> None: ... +def set___main___attrs(id: SupportsIndex, updates: Mapping[str, object], *, 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: ... + +WHENCE_UNKNOWN: Final[Literal[0]] +WHENCE_RUNTIME: Final[Literal[1]] +WHENCE_LEGACY_CAPI: Final[Literal[2]] +WHENCE_CAPI: Final[Literal[3]] +WHENCE_XI: Final[Literal[4]] +WHENCE_STDLIB: Final[Literal[5]] From 17f0eec6006be5336df7daf1df1b3406260e71eb Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:44:20 -0400 Subject: [PATCH 02/14] Tweak --- stdlib/_interpeters.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/_interpeters.pyi b/stdlib/_interpeters.pyi index 2101b7f345cf..9dd42f18335f 100644 --- a/stdlib/_interpeters.pyi +++ b/stdlib/_interpeters.pyi @@ -7,7 +7,8 @@ class InterpreterNotShareableError(InterpreterError): ... # Not-instantiable, so mark as final. @final -class CrossInterpreterBufferView: ... +class CrossInterpreterBufferView: + def __buffer__(self, flags: int, /) -> memoryview: ... def new_config( name: Literal["default", "isolated", "legacy", "empty"] = "isolated", From cd7158fd1cf9220b11bf4b4411f4d6e29ae3425f Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:46:40 -0400 Subject: [PATCH 03/14] Naming fix --- stdlib/{_interpeters.pyi => _interpreters.pyi} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stdlib/{_interpeters.pyi => _interpreters.pyi} (100%) diff --git a/stdlib/_interpeters.pyi b/stdlib/_interpreters.pyi similarity index 100% rename from stdlib/_interpeters.pyi rename to stdlib/_interpreters.pyi From f6d4140ffeb8f8419b624fe74bd38aeed0dcc72c Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:47:21 -0400 Subject: [PATCH 04/14] Only for 3.13+ --- stdlib/VERSIONS | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 89754f65f3fa..f14c85e8a364 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -35,6 +35,7 @@ _dummy_threading: 3.0-3.8 _heapq: 3.0- _imp: 3.0- _interpchannels: 3.13- +_interpreters: 3.13- _json: 3.0- _locale: 3.0- _lsprof: 3.0- From 363e1d4254d15eced06a84eade65ae642fb2f7cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 20:47:59 +0000 Subject: [PATCH 05/14] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_interpreters.pyi | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 9dd42f18335f..bc52532b73a9 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -11,14 +11,10 @@ class CrossInterpreterBufferView: def __buffer__(self, flags: int, /) -> memoryview: ... def new_config( - name: Literal["default", "isolated", "legacy", "empty"] = "isolated", - /, - **overides: object, + name: Literal["default", "isolated", "legacy", "empty"] = "isolated", /, **overides: object ) -> types.SimpleNamespace: ... def create( - config: types.SimpleNamespace | Literal["isolated", "legacy"] | None = "isolated", - *, - reqrefs: bool = False, + config: types.SimpleNamespace | Literal["isolated", "legacy"] | None = "isolated", *, reqrefs: bool = False ) -> int: ... def destroy(id: SupportsIndex, *, restrict: bool = False) -> None: ... def list_all(*, require_ready: bool) -> list[tuple[int, int]]: ... From cc87b4008e3fe6fb41382424f4af94ab919c709e Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:52:42 -0400 Subject: [PATCH 06/14] Fix linting issues --- stdlib/_interpreters.pyi | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index bc52532b73a9..5d32a515b3a0 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -1,5 +1,6 @@ import types -from typing import Callable, Final, Literal, Mapping, SupportsIndex, final +from collections.abc import Callable, Mapping +from typing import Final, Literal, SupportsIndex, final class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... @@ -40,9 +41,9 @@ def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ... def is_shareable(obj: object) -> bool: ... def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace: ... -WHENCE_UNKNOWN: Final[Literal[0]] -WHENCE_RUNTIME: Final[Literal[1]] -WHENCE_LEGACY_CAPI: Final[Literal[2]] -WHENCE_CAPI: Final[Literal[3]] -WHENCE_XI: Final[Literal[4]] -WHENCE_STDLIB: Final[Literal[5]] +WHENCE_UNKNOWN: Final = 0 +WHENCE_RUNTIME: Final = 1 +WHENCE_LEGACY_CAPI: Final = 2 +WHENCE_CAPI: Final = 3 +WHENCE_XI: Final = 4 +WHENCE_STDLIB: Final = 5 From 46d0563565abb577b9400ab8368ab22bc0db722a Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:57:45 -0400 Subject: [PATCH 07/14] Fix --- stdlib/_interpreters.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 5d32a515b3a0..29d17bb0e6ab 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -4,7 +4,7 @@ from typing import Final, Literal, SupportsIndex, final class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... -class InterpreterNotShareableError(InterpreterError): ... +class NotShareableError(InterpreterError): ... # Not-instantiable, so mark as final. @final From f77b2be1ac99eceadc819af56a6a36d5bd811712 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:59:23 -0400 Subject: [PATCH 08/14] Fix --- stdlib/_interpreters.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 29d17bb0e6ab..9d985ce90140 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -4,7 +4,7 @@ from typing import Final, Literal, SupportsIndex, final class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... -class NotShareableError(InterpreterError): ... +class NotShareableError(Exception): ... # Not-instantiable, so mark as final. @final From 4fb596c0d2a5cf5dc0bd28426162fc66dbcc219b Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 30 Jun 2024 13:11:30 -0500 Subject: [PATCH 09/14] Fix configs --- stdlib/_interpreters.pyi | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 9d985ce90140..6395ac7af148 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -1,6 +1,9 @@ import types from collections.abc import Callable, Mapping from typing import Final, Literal, SupportsIndex, final +from typing_extensions import TypeAlias + +_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty"] class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... @@ -11,12 +14,8 @@ class NotShareableError(Exception): ... class CrossInterpreterBufferView: def __buffer__(self, flags: int, /) -> memoryview: ... -def new_config( - name: Literal["default", "isolated", "legacy", "empty"] = "isolated", /, **overides: object -) -> types.SimpleNamespace: ... -def create( - config: types.SimpleNamespace | Literal["isolated", "legacy"] | None = "isolated", *, reqrefs: bool = False -) -> int: ... +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]: ... From ef338069a1f2094dc4e8ecbffc63305c696ad5ed Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:41:07 -0500 Subject: [PATCH 10/14] Add empty string in Configs --- stdlib/_interpreters.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 6395ac7af148..ec685d077d53 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -3,7 +3,7 @@ from collections.abc import Callable, Mapping from typing import Final, Literal, SupportsIndex, final from typing_extensions import TypeAlias -_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty"] +_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""] class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... From 9cd08daaf26beb6c2ad3cac3cc888078a1957fb4 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:53:22 -0500 Subject: [PATCH 11/14] Address comments --- stdlib/_interpreters.pyi | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index ec685d077d53..7ee27ff1beac 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -32,8 +32,20 @@ def call( *, restrict: bool = False, ) -> object: ... -def run_string(id: SupportsIndex, script: str, shared: bool | None = None, *, restrict: bool = False) -> None: ... -def run_func(id: SupportsIndex, func: Callable[..., object], shared: bool | None = None, *, restrict: bool = False) -> None: ... +def run_string( + id: SupportsIndex, + script: str | types.CodeType | Callable[[], object], + shared: bool | None = None, + *, + restrict: bool = False, +) -> None: ... +def run_func( + id: SupportsIndex, + func: types.CodeType | Callable[[], object], + shared: bool | None = None, + *, + restrict: bool = False, +) -> None: ... def set___main___attrs(id: SupportsIndex, updates: Mapping[str, object], *, restrict: bool = False) -> None: ... def incref(id: SupportsIndex, *, implieslink: bool = False, restrict: bool = False) -> None: ... def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ... From a6aabd9a70ac9064c7732d16cd79c256c6972cf4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:54:57 +0000 Subject: [PATCH 12/14] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_interpreters.pyi | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 7ee27ff1beac..2bc96da5dd42 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -33,18 +33,10 @@ def call( restrict: bool = False, ) -> object: ... def run_string( - id: SupportsIndex, - script: str | types.CodeType | Callable[[], object], - shared: bool | None = None, - *, - restrict: bool = False, + id: SupportsIndex, script: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False ) -> None: ... def run_func( - id: SupportsIndex, - func: types.CodeType | Callable[[], object], - shared: bool | None = None, - *, - restrict: bool = False, + id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False ) -> None: ... def set___main___attrs(id: SupportsIndex, updates: Mapping[str, object], *, restrict: bool = False) -> None: ... def incref(id: SupportsIndex, *, implieslink: bool = False, restrict: bool = False) -> None: ... From 626eea2419e86920e333a3b5efe3e36af4162bf7 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:55:11 -0500 Subject: [PATCH 13/14] Modify comment --- stdlib/_interpreters.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 2bc96da5dd42..2c2c1f1d0846 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -9,7 +9,7 @@ class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... class NotShareableError(Exception): ... -# Not-instantiable, so mark as final. +# Not-instantiable, so we don't see a reason to allow subclassing. @final class CrossInterpreterBufferView: def __buffer__(self, flags: int, /) -> memoryview: ... From 9cb5a5915014601bd00812adca7537bf1425b2cd Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 3 Jul 2024 23:10:25 -0500 Subject: [PATCH 14/14] Remove final --- stdlib/_interpreters.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 2c2c1f1d0846..75f661a7e8e1 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -1,6 +1,6 @@ import types from collections.abc import Callable, Mapping -from typing import Final, Literal, SupportsIndex, final +from typing import Final, Literal, SupportsIndex from typing_extensions import TypeAlias _Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""] @@ -9,8 +9,6 @@ class InterpreterError(Exception): ... class InterpreterNotFoundError(InterpreterError): ... class NotShareableError(Exception): ... -# Not-instantiable, so we don't see a reason to allow subclassing. -@final class CrossInterpreterBufferView: def __buffer__(self, flags: int, /) -> memoryview: ...