Skip to content

Commit 3281e6b

Browse files
+ Made more type-safe, Closes #32
1 parent 226aa1d commit 3281e6b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/thread/decorators.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
T = TypeVar('T')
1616
P = ParamSpec('P')
1717
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]]
2020
FullParamReturn = Callable[P, Thread]
21-
WrappedWithParamReturn = Callable[[TargetFunction], WithParamReturn]
21+
WrappedWithParamReturn = Callable[[TargetFunction[P]], WithParamReturn[P, T]]
2222

2323

2424
@overload
25-
def threaded(__function: TargetFunction) -> NoParamReturn: ...
25+
def threaded(__function: TargetFunction[P]) -> NoParamReturn[P, T]: ...
2626

2727
@overload
2828
def threaded(
@@ -32,7 +32,7 @@ def threaded(
3232
ignore_errors: Sequence[type[Exception]] = (),
3333
suppress_errors: bool = False,
3434
**overflow_kwargs: Overflow_In
35-
) -> WithParamReturn: ...
35+
) -> WithParamReturn[P, T]: ...
3636

3737
@overload
3838
def threaded(
@@ -43,18 +43,18 @@ def threaded(
4343
ignore_errors: Sequence[type[Exception]] = (),
4444
suppress_errors: bool = False,
4545
**overflow_kwargs: Overflow_In
46-
) -> FullParamReturn: ...
46+
) -> FullParamReturn[P]: ...
4747

4848

4949
def threaded(
50-
__function: Optional[TargetFunction] = None,
50+
__function: Optional[TargetFunction[P]] = None,
5151
*,
5252
args: Sequence[Data_In] = (),
5353
kwargs: Mapping[str, Data_In] = {},
5454
ignore_errors: Sequence[type[Exception]] = (),
5555
suppress_errors: bool = False,
5656
**overflow_kwargs: Overflow_In
57-
) -> Union[NoParamReturn, WithParamReturn, FullParamReturn]:
57+
) -> Union[NoParamReturn[P, T], WithParamReturn[P, T], FullParamReturn[P]]:
5858
"""
5959
Decorate a function to run it in a thread
6060
@@ -96,7 +96,7 @@ def threaded(
9696
"""
9797

9898
if not callable(__function):
99-
def wrapper(func: TargetFunction) -> FullParamReturn:
99+
def wrapper(func: TargetFunction[P]) -> FullParamReturn[P]:
100100
return threaded(
101101
func,
102102
args = args,

0 commit comments

Comments
 (0)