From e6f764cd25dd6a1faa22d6a907cb2b019f449d67 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 1 Jan 2025 20:37:51 -0600 Subject: [PATCH 1/5] Fix types in `_interpqueues` and `_interpreters` --- stdlib/_interpqueues.pyi | 14 ++++++++------ stdlib/_interpreters.pyi | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/stdlib/_interpqueues.pyi b/stdlib/_interpqueues.pyi index db5e4cff5068..da0f13140613 100644 --- a/stdlib/_interpqueues.pyi +++ b/stdlib/_interpqueues.pyi @@ -1,16 +1,18 @@ -from typing import Any, SupportsIndex +from typing import Any, Literal, SupportsIndex + +UnboundOp = Literal[1, 2, 3] class QueueError(RuntimeError): ... class QueueNotFoundError(QueueError): ... def bind(qid: SupportsIndex) -> None: ... -def create(maxsize: SupportsIndex, fmt: SupportsIndex) -> int: ... +def create(maxsize: SupportsIndex, fmt: SupportsIndex, unboundop: UnboundOp) -> int: ... def destroy(qid: SupportsIndex) -> None: ... -def get(qid: SupportsIndex) -> tuple[Any, int]: ... +def get(qid: SupportsIndex) -> tuple[Any, int, UnboundOp | None]: ... def get_count(qid: SupportsIndex) -> int: ... def get_maxsize(qid: SupportsIndex) -> int: ... -def get_queue_defaults(qid: SupportsIndex) -> tuple[int]: ... +def get_queue_defaults(qid: SupportsIndex) -> tuple[int, UnboundOp]: ... def is_full(qid: SupportsIndex) -> bool: ... -def list_all() -> list[tuple[int, int]]: ... -def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex) -> None: ... +def list_all() -> list[tuple[int, int, UnboundOp]]: ... +def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex, unboundop: UnboundOp) -> None: ... def release(qid: SupportsIndex) -> None: ... diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index a57ef13c6d0f..490fd564f37d 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -21,7 +21,13 @@ 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 exec( + id: SupportsIndex, + code: str | types.CodeType, + shared: bool | None = None, + *, + restrict: bool = False, +) -> None | types.SimpleNamespace: ... def call( id: SupportsIndex, callable: Callable[..., object], From 5c4d557579ad32061966feaf9a6fe9848648b4e2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 02:41:51 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_interpreters.pyi | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 490fd564f37d..2b64459e8ace 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -22,11 +22,7 @@ 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 | types.CodeType, - shared: bool | None = None, - *, - restrict: bool = False, + id: SupportsIndex, code: str | types.CodeType, shared: bool | None = None, *, restrict: bool = False ) -> None | types.SimpleNamespace: ... def call( id: SupportsIndex, From 5849d976fc384df617aa4b3407698502a78e2bcd Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 1 Jan 2025 20:42:13 -0600 Subject: [PATCH 3/5] _UnboundOp should be private --- stdlib/_interpqueues.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/_interpqueues.pyi b/stdlib/_interpqueues.pyi index da0f13140613..b23baa474bcf 100644 --- a/stdlib/_interpqueues.pyi +++ b/stdlib/_interpqueues.pyi @@ -1,18 +1,18 @@ from typing import Any, Literal, SupportsIndex -UnboundOp = Literal[1, 2, 3] +_UnboundOp = Literal[1, 2, 3] class QueueError(RuntimeError): ... class QueueNotFoundError(QueueError): ... def bind(qid: SupportsIndex) -> None: ... -def create(maxsize: SupportsIndex, fmt: SupportsIndex, unboundop: UnboundOp) -> int: ... +def create(maxsize: SupportsIndex, fmt: SupportsIndex, unboundop: _UnboundOp) -> int: ... def destroy(qid: SupportsIndex) -> None: ... -def get(qid: SupportsIndex) -> tuple[Any, int, UnboundOp | None]: ... +def get(qid: SupportsIndex) -> tuple[Any, int, _UnboundOp | None]: ... def get_count(qid: SupportsIndex) -> int: ... def get_maxsize(qid: SupportsIndex) -> int: ... -def get_queue_defaults(qid: SupportsIndex) -> tuple[int, UnboundOp]: ... +def get_queue_defaults(qid: SupportsIndex) -> tuple[int, _UnboundOp]: ... def is_full(qid: SupportsIndex) -> bool: ... -def list_all() -> list[tuple[int, int, UnboundOp]]: ... -def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex, unboundop: UnboundOp) -> None: ... +def list_all() -> list[tuple[int, int, _UnboundOp]]: ... +def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex, unboundop: _UnboundOp) -> None: ... def release(qid: SupportsIndex) -> None: ... From 9452e9ec62072c40dff63b0c64a11bd666ff12ff Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Wed, 1 Jan 2025 20:46:23 -0600 Subject: [PATCH 4/5] Use TypeAlias --- stdlib/_interpqueues.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/_interpqueues.pyi b/stdlib/_interpqueues.pyi index b23baa474bcf..c9323b106f3d 100644 --- a/stdlib/_interpqueues.pyi +++ b/stdlib/_interpqueues.pyi @@ -1,6 +1,7 @@ from typing import Any, Literal, SupportsIndex +from typing_extensions import TypeAlias -_UnboundOp = Literal[1, 2, 3] +_UnboundOp: TypeAlias = Literal[1, 2, 3] class QueueError(RuntimeError): ... class QueueNotFoundError(QueueError): ... From c78b6aa2fddf16c03e38c78c4e0e5e92e9c5da14 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:52:00 -0600 Subject: [PATCH 5/5] Add callable for `code` in `exec` --- stdlib/_interpreters.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_interpreters.pyi b/stdlib/_interpreters.pyi index 2b64459e8ace..caa1115e9d3d 100644 --- a/stdlib/_interpreters.pyi +++ b/stdlib/_interpreters.pyi @@ -22,7 +22,7 @@ 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 | types.CodeType, shared: bool | None = None, *, restrict: bool = False + id: SupportsIndex, code: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False ) -> None | types.SimpleNamespace: ... def call( id: SupportsIndex,