Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
# TODO: New errors in Python 3.14 that need to be fixed or moved below
# ====================================================================

concurrent.futures.InterpreterPoolExecutor.__init__
concurrent.futures.InterpreterPoolExecutor.prepare_context
concurrent.futures.interpreter.ExecutionFailed
concurrent.futures.interpreter.InterpreterPoolExecutor.__init__
concurrent.futures.interpreter.InterpreterPoolExecutor.prepare_context
concurrent.futures.interpreter.WorkerContext.__init__
concurrent.futures.interpreter.WorkerContext.prepare
concurrent.futures.interpreter.do_call
multiprocessing.managers.BaseListProxy.clear
multiprocessing.managers.BaseListProxy.copy
multiprocessing.managers.DictProxy.__ior__
Expand Down
2 changes: 1 addition & 1 deletion stdlib/@tests/test_cases/check_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def check_interpreter_pool_executor() -> None:
with InterpreterPoolExecutor(initializer=_initializer, initargs=("x",)): # type: ignore
...

context = InterpreterPoolExecutor.prepare_context(initializer=_initializer, initargs=(1,), shared={})
context = InterpreterPoolExecutor.prepare_context(initializer=_initializer, initargs=(1,))
worker_context = context[0]()
assert_type(worker_context, concurrent.futures.interpreter.WorkerContext)
resolve_task = context[1]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_interpreters.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def exec(
def call(
id: SupportsIndex,
callable: Callable[..., _R],
args: tuple[object, ...] | None = None,
kwargs: dict[str, object] | None = None,
args: tuple[Any, ...] | None = None,
kwargs: dict[str, Any] | None = None,
*,
restrict: bool = False,
) -> tuple[_R, types.SimpleNamespace]: ...
Expand Down
59 changes: 19 additions & 40 deletions stdlib/concurrent/futures/interpreter.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import sys
from collections.abc import Callable, Mapping
from collections.abc import Callable
from concurrent.futures import ThreadPoolExecutor
from typing import Literal, Protocol, overload, type_check_only
from typing import Any, Literal, Protocol, overload, type_check_only
from typing_extensions import ParamSpec, Self, TypeAlias, TypeVar, TypeVarTuple, Unpack

_Task: TypeAlias = tuple[bytes, Literal["function", "script"]]
_Ts = TypeVarTuple("_Ts")
_P = ParamSpec("_P")
_R = TypeVar("_R")

@type_check_only
class _TaskFunc(Protocol):
Expand All @@ -13,62 +16,41 @@ class _TaskFunc(Protocol):
@overload
def __call__(self, fn: str) -> tuple[bytes, Literal["script"]]: ...

_Ts = TypeVarTuple("_Ts")
_P = ParamSpec("_P")
_R = TypeVar("_R")

# A `type.simplenamespace` with `__name__` attribute.
@type_check_only
class _HasName(Protocol):
__name__: str

# `_interpreters.exec` technically gives us a simple namespace.
@type_check_only
class _ExcInfo(Protocol):
formatted: str
msg: str
type: _HasName

if sys.version_info >= (3, 14):
from concurrent.futures.thread import BrokenThreadPool, WorkerContext as ThreadWorkerContext
from concurrent.interpreters import Interpreter, Queue

from _interpreters import InterpreterError

class ExecutionFailed(InterpreterError):
def __init__(self, excinfo: _ExcInfo) -> None: ... # type: ignore[override]
def do_call(results: Queue, func: Callable[..., _R], args: tuple[Any, ...], kwargs: dict[str, Any]) -> _R: ...

class WorkerContext(ThreadWorkerContext):
# Parent class doesn't have `shared` argument,
@overload # type: ignore[override]
interp: Interpreter | None
results: Queue | None
@overload # type: ignore[override]
@classmethod
def prepare(
cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]], shared: Mapping[str, object]
cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]]
) -> tuple[Callable[[], Self], _TaskFunc]: ...
@overload # type: ignore[override]
@overload
@classmethod
def prepare(
cls, initializer: Callable[[], object], initargs: tuple[()], shared: Mapping[str, object]
) -> tuple[Callable[[], Self], _TaskFunc]: ...
def __init__(
self, initdata: tuple[bytes, Literal["function", "script"]], shared: Mapping[str, object] | None = None
) -> None: ... # type: ignore[override]
def prepare(cls, initializer: Callable[[], object], initargs: tuple[()]) -> tuple[Callable[[], Self], _TaskFunc]: ...
def __init__(self, initdata: _Task) -> None: ...
def __del__(self) -> None: ...
def run(self, task: _Task) -> None: ... # type: ignore[override]
def run(self, task: _Task) -> None: ... # type: ignore[override]

class BrokenInterpreterPool(BrokenThreadPool): ...

class InterpreterPoolExecutor(ThreadPoolExecutor):
BROKEN: type[BrokenInterpreterPool]

@overload # type: ignore[override]
@overload # type: ignore[override]
@classmethod
def prepare_context(
cls, initializer: Callable[[], object], initargs: tuple[()], shared: Mapping[str, object]
cls, initializer: Callable[[], object], initargs: tuple[()]
) -> tuple[Callable[[], WorkerContext], _TaskFunc]: ...
@overload # type: ignore[override]
@overload
@classmethod
def prepare_context(
cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]], shared: Mapping[str, object]
cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]]
) -> tuple[Callable[[], WorkerContext], _TaskFunc]: ...
@overload
def __init__(
Expand All @@ -77,7 +59,6 @@ if sys.version_info >= (3, 14):
thread_name_prefix: str = "",
initializer: Callable[[], object] | None = None,
initargs: tuple[()] = (),
shared: Mapping[str, object] | None = None,
) -> None: ...
@overload
def __init__(
Expand All @@ -87,7 +68,6 @@ if sys.version_info >= (3, 14):
*,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
shared: Mapping[str, object] | None = None,
) -> None: ...
@overload
def __init__(
Expand All @@ -96,5 +76,4 @@ if sys.version_info >= (3, 14):
thread_name_prefix: str,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
shared: Mapping[str, object] | None = None,
) -> None: ...
Loading