1
1
import sys
2
- from collections .abc import Callable , Mapping
2
+ from collections .abc import Callable
3
3
from 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
5
5
from typing_extensions import ParamSpec , Self , TypeAlias , TypeVar , TypeVarTuple , Unpack
6
6
7
7
_Task : TypeAlias = tuple [bytes , Literal ["function" , "script" ]]
8
+ _Ts = TypeVarTuple ("_Ts" )
9
+ _P = ParamSpec ("_P" )
10
+ _R = TypeVar ("_R" )
8
11
9
12
@type_check_only
10
13
class _TaskFunc (Protocol ):
@@ -13,62 +16,41 @@ class _TaskFunc(Protocol):
13
16
@overload
14
17
def __call__ (self , fn : str ) -> tuple [bytes , Literal ["script" ]]: ...
15
18
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
-
32
19
if sys .version_info >= (3 , 14 ):
33
20
from concurrent .futures .thread import BrokenThreadPool , WorkerContext as ThreadWorkerContext
21
+ from concurrent .interpreters import Interpreter , Queue
34
22
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 : ...
39
24
40
25
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]
43
29
@classmethod
44
30
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 ]]
46
32
) -> tuple [Callable [[], Self ], _TaskFunc ]: ...
47
- @overload # type: ignore[override]
33
+ @overload
48
34
@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 : ...
55
37
def __del__ (self ) -> None : ...
56
- def run (self , task : _Task ) -> None : ... # type: ignore[override]
38
+ def run (self , task : _Task ) -> None : ... # type: ignore[override]
57
39
58
40
class BrokenInterpreterPool (BrokenThreadPool ): ...
59
41
60
42
class InterpreterPoolExecutor (ThreadPoolExecutor ):
61
43
BROKEN : type [BrokenInterpreterPool ]
62
44
63
- @overload # type: ignore[override]
45
+ @overload # type: ignore[override]
64
46
@classmethod
65
47
def prepare_context (
66
- cls , initializer : Callable [[], object ], initargs : tuple [()], shared : Mapping [ str , object ]
48
+ cls , initializer : Callable [[], object ], initargs : tuple [()]
67
49
) -> tuple [Callable [[], WorkerContext ], _TaskFunc ]: ...
68
- @overload # type: ignore[override]
50
+ @overload
69
51
@classmethod
70
52
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 ]]
72
54
) -> tuple [Callable [[], WorkerContext ], _TaskFunc ]: ...
73
55
@overload
74
56
def __init__ (
@@ -77,7 +59,6 @@ if sys.version_info >= (3, 14):
77
59
thread_name_prefix : str = "" ,
78
60
initializer : Callable [[], object ] | None = None ,
79
61
initargs : tuple [()] = (),
80
- shared : Mapping [str , object ] | None = None ,
81
62
) -> None : ...
82
63
@overload
83
64
def __init__ (
@@ -87,7 +68,6 @@ if sys.version_info >= (3, 14):
87
68
* ,
88
69
initializer : Callable [[Unpack [_Ts ]], object ],
89
70
initargs : tuple [Unpack [_Ts ]],
90
- shared : Mapping [str , object ] | None = None ,
91
71
) -> None : ...
92
72
@overload
93
73
def __init__ (
@@ -96,5 +76,4 @@ if sys.version_info >= (3, 14):
96
76
thread_name_prefix : str ,
97
77
initializer : Callable [[Unpack [_Ts ]], object ],
98
78
initargs : tuple [Unpack [_Ts ]],
99
- shared : Mapping [str , object ] | None = None ,
100
79
) -> None : ...
0 commit comments