15
15
T = TypeVar ('T' )
16
16
P = ParamSpec ('P' )
17
17
TargetFunction = Callable [P , Data_Out ]
18
- NoParamReturn = Callable [P , Thread ]
19
- WithParamReturn = Callable [[TargetFunction ] , NoParamReturn ]
18
+ NoParamReturn = Callable [P , Thread [ P , T ] ]
19
+ WithParamReturn = Callable [[TargetFunction [ P ]] , NoParamReturn [ P , T ] ]
20
20
FullParamReturn = Callable [P , Thread ]
21
- WrappedWithParamReturn = Callable [[TargetFunction ] , WithParamReturn ]
21
+ WrappedWithParamReturn = Callable [[TargetFunction [ P ]] , WithParamReturn [ P , T ] ]
22
22
23
23
24
24
@overload
25
- def threaded (__function : TargetFunction ) -> NoParamReturn : ...
25
+ def threaded (__function : TargetFunction [ P ] ) -> NoParamReturn [ P , T ] : ...
26
26
27
27
@overload
28
28
def threaded (
@@ -32,7 +32,7 @@ def threaded(
32
32
ignore_errors : Sequence [type [Exception ]] = (),
33
33
suppress_errors : bool = False ,
34
34
** overflow_kwargs : Overflow_In
35
- ) -> WithParamReturn : ...
35
+ ) -> WithParamReturn [ P , T ] : ...
36
36
37
37
@overload
38
38
def threaded (
@@ -43,18 +43,18 @@ def threaded(
43
43
ignore_errors : Sequence [type [Exception ]] = (),
44
44
suppress_errors : bool = False ,
45
45
** overflow_kwargs : Overflow_In
46
- ) -> FullParamReturn : ...
46
+ ) -> FullParamReturn [ P ] : ...
47
47
48
48
49
49
def threaded (
50
- __function : Optional [TargetFunction ] = None ,
50
+ __function : Optional [TargetFunction [ P ] ] = None ,
51
51
* ,
52
52
args : Sequence [Data_In ] = (),
53
53
kwargs : Mapping [str , Data_In ] = {},
54
54
ignore_errors : Sequence [type [Exception ]] = (),
55
55
suppress_errors : bool = False ,
56
56
** overflow_kwargs : Overflow_In
57
- ) -> Union [NoParamReturn , WithParamReturn , FullParamReturn ]:
57
+ ) -> Union [NoParamReturn [ P , T ], WithParamReturn [ P , T ], FullParamReturn [ P ] ]:
58
58
"""
59
59
Decorate a function to run it in a thread
60
60
@@ -96,7 +96,7 @@ def threaded(
96
96
"""
97
97
98
98
if not callable (__function ):
99
- def wrapper (func : TargetFunction ) -> FullParamReturn :
99
+ def wrapper (func : TargetFunction [ P ] ) -> FullParamReturn [ P ] :
100
100
return threaded (
101
101
func ,
102
102
args = args ,
0 commit comments