11import sys
2- from collections .abc import Callable , Mapping
2+ from collections .abc import Callable
33from concurrent .futures import ThreadPoolExecutor
4- from typing import Literal , Protocol , overload , type_check_only
4+ from typing import Any , Literal , Protocol , overload , type_check_only
55from typing_extensions import ParamSpec , Self , TypeAlias , TypeVar , TypeVarTuple , Unpack
66
77_Task : TypeAlias = tuple [bytes , Literal ["function" , "script" ]]
8+ _Ts = TypeVarTuple ("_Ts" )
9+ _P = ParamSpec ("_P" )
10+ _R = TypeVar ("_R" )
811
912@type_check_only
1013class _TaskFunc (Protocol ):
@@ -13,62 +16,41 @@ class _TaskFunc(Protocol):
1316 @overload
1417 def __call__ (self , fn : str ) -> tuple [bytes , Literal ["script" ]]: ...
1518
16- _Ts = TypeVarTuple ("_Ts" )
17- _P = ParamSpec ("_P" )
18- _R = TypeVar ("_R" )
19-
20- # A `type.simplenamespace` with `__name__` attribute.
21- @type_check_only
22- class _HasName (Protocol ):
23- __name__ : str
24-
25- # `_interpreters.exec` technically gives us a simple namespace.
26- @type_check_only
27- class _ExcInfo (Protocol ):
28- formatted : str
29- msg : str
30- type : _HasName
31-
3219if sys .version_info >= (3 , 14 ):
3320 from concurrent .futures .thread import BrokenThreadPool , WorkerContext as ThreadWorkerContext
21+ from concurrent .interpreters import Interpreter , Queue
3422
35- from _interpreters import InterpreterError
36-
37- class ExecutionFailed (InterpreterError ):
38- def __init__ (self , excinfo : _ExcInfo ) -> None : ... # type: ignore[override]
23+ def do_call (results : Queue , func : Callable [..., _R ], args : tuple [Any , ...], kwargs : dict [str , Any ]) -> _R : ...
3924
4025 class WorkerContext (ThreadWorkerContext ):
41- # Parent class doesn't have `shared` argument,
42- @overload # type: ignore[override]
26+ interp : Interpreter | None
27+ results : Queue | None
28+ @overload # type: ignore[override]
4329 @classmethod
4430 def prepare (
45- cls , initializer : Callable [[Unpack [_Ts ]], object ], initargs : tuple [Unpack [_Ts ]], shared : Mapping [ str , object ]
31+ cls , initializer : Callable [[Unpack [_Ts ]], object ], initargs : tuple [Unpack [_Ts ]]
4632 ) -> tuple [Callable [[], Self ], _TaskFunc ]: ...
47- @overload # type: ignore[override]
33+ @overload
4834 @classmethod
49- def prepare (
50- cls , initializer : Callable [[], object ], initargs : tuple [()], shared : Mapping [str , object ]
51- ) -> tuple [Callable [[], Self ], _TaskFunc ]: ...
52- def __init__ (
53- self , initdata : tuple [bytes , Literal ["function" , "script" ]], shared : Mapping [str , object ] | None = None
54- ) -> None : ... # type: ignore[override]
35+ def prepare (cls , initializer : Callable [[], object ], initargs : tuple [()]) -> tuple [Callable [[], Self ], _TaskFunc ]: ...
36+ def __init__ (self , initdata : _Task ) -> None : ...
5537 def __del__ (self ) -> None : ...
56- def run (self , task : _Task ) -> None : ... # type: ignore[override]
38+ def run (self , task : _Task ) -> None : ... # type: ignore[override]
5739
5840 class BrokenInterpreterPool (BrokenThreadPool ): ...
5941
6042 class InterpreterPoolExecutor (ThreadPoolExecutor ):
6143 BROKEN : type [BrokenInterpreterPool ]
6244
63- @overload # type: ignore[override]
45+ @overload # type: ignore[override]
6446 @classmethod
6547 def prepare_context (
66- cls , initializer : Callable [[], object ], initargs : tuple [()], shared : Mapping [ str , object ]
48+ cls , initializer : Callable [[], object ], initargs : tuple [()]
6749 ) -> tuple [Callable [[], WorkerContext ], _TaskFunc ]: ...
68- @overload # type: ignore[override]
50+ @overload
6951 @classmethod
7052 def prepare_context (
71- cls , initializer : Callable [[Unpack [_Ts ]], object ], initargs : tuple [Unpack [_Ts ]], shared : Mapping [ str , object ]
53+ cls , initializer : Callable [[Unpack [_Ts ]], object ], initargs : tuple [Unpack [_Ts ]]
7254 ) -> tuple [Callable [[], WorkerContext ], _TaskFunc ]: ...
7355 @overload
7456 def __init__ (
@@ -77,7 +59,6 @@ if sys.version_info >= (3, 14):
7759 thread_name_prefix : str = "" ,
7860 initializer : Callable [[], object ] | None = None ,
7961 initargs : tuple [()] = (),
80- shared : Mapping [str , object ] | None = None ,
8162 ) -> None : ...
8263 @overload
8364 def __init__ (
@@ -87,7 +68,6 @@ if sys.version_info >= (3, 14):
8768 * ,
8869 initializer : Callable [[Unpack [_Ts ]], object ],
8970 initargs : tuple [Unpack [_Ts ]],
90- shared : Mapping [str , object ] | None = None ,
9171 ) -> None : ...
9272 @overload
9373 def __init__ (
@@ -96,5 +76,4 @@ if sys.version_info >= (3, 14):
9676 thread_name_prefix : str ,
9777 initializer : Callable [[Unpack [_Ts ]], object ],
9878 initargs : tuple [Unpack [_Ts ]],
99- shared : Mapping [str , object ] | None = None ,
10079 ) -> None : ...
0 commit comments