Skip to content

Commit 0aa73c4

Browse files
feat: Update thread.processor to support the new dataset typing
1 parent 2974c6b commit 0aa73c4

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/thread/decorators/_processor.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,44 @@
77
from functools import wraps
88
from ..thread import ParallelProcessing
99

10-
from .._types import Overflow_In, Data_In
11-
from typing import Callable, Mapping, Sequence, Optional, Union, overload
10+
from .._types import (
11+
Overflow_In,
12+
Data_In,
13+
SupportsGetItem,
14+
SupportsLength,
15+
SupportsLengthGetItem,
16+
)
17+
from typing import Any, Callable, Mapping, Sequence, Optional, Union, overload
1218
from typing_extensions import ParamSpec, TypeVar, Concatenate
1319

1420

1521
_TargetT = TypeVar('_TargetT')
1622
_TargetP = ParamSpec('_TargetP')
1723
_DataT = TypeVar('_DataT')
1824
TargetFunction = Callable[Concatenate[_DataT, _TargetP], _TargetT]
25+
Dataset = Union[
26+
SupportsLengthGetItem[_DataT], SupportsGetItem[_DataT], SupportsLength, Any
27+
]
1928

2029

2130
NoParamReturn = Callable[
22-
Concatenate[Sequence[_DataT], _TargetP],
31+
Concatenate[Dataset[_DataT], _TargetP],
2332
ParallelProcessing[_TargetP, _TargetT, _DataT],
2433
]
2534
WithParamReturn = Callable[
2635
[TargetFunction[_DataT, _TargetP, _TargetT]],
2736
NoParamReturn[_DataT, _TargetP, _TargetT],
2837
]
2938
FullParamReturn = Callable[
30-
Concatenate[Sequence[_DataT], _TargetP],
39+
Concatenate[Dataset[_DataT], _TargetP],
3140
ParallelProcessing[_TargetP, _TargetT, _DataT],
3241
]
3342

3443

3544
@overload
3645
def processor(
3746
__function: TargetFunction[_DataT, _TargetP, _TargetT],
38-
) -> NoParamReturn[_DataT, _TargetP, _TargetT]:
39-
...
47+
) -> NoParamReturn[_DataT, _TargetP, _TargetT]: ...
4048

4149

4250
@overload
@@ -47,8 +55,7 @@ def processor(
4755
ignore_errors: Sequence[type[Exception]] = (),
4856
suppress_errors: bool = False,
4957
**overflow_kwargs: Overflow_In,
50-
) -> WithParamReturn[_DataT, _TargetP, _TargetT]:
51-
...
58+
) -> WithParamReturn[_DataT, _TargetP, _TargetT]: ...
5259

5360

5461
@overload
@@ -60,8 +67,7 @@ def processor(
6067
ignore_errors: Sequence[type[Exception]] = (),
6168
suppress_errors: bool = False,
6269
**overflow_kwargs: Overflow_In,
63-
) -> FullParamReturn[_DataT, _TargetP, _TargetT]:
64-
...
70+
) -> FullParamReturn[_DataT, _TargetP, _TargetT]: ...
6571

6672

6773
def processor(
@@ -106,8 +112,7 @@ def processor(
106112
107113
You can also pass keyword arguments to change the thread behaviour, it otherwise follows the defaults of `thread.Thread`
108114
>>> @thread.threaded(daemon = True)
109-
>>> def myfunction():
110-
... ...
115+
>>> def myfunction(): ...
111116
112117
Args will be ordered infront of function-parsed args parsed into `thread.Thread.args`
113118
>>> @thread.threaded(args = (1))
@@ -142,7 +147,7 @@ def wrapper(
142147

143148
@wraps(__function)
144149
def wrapped(
145-
data: Sequence[_DataT],
150+
data: Dataset[_DataT],
146151
*parsed_args: _TargetP.args,
147152
**parsed_kwargs: _TargetP.kwargs,
148153
) -> ParallelProcessing[_TargetP, _TargetT, _DataT]:

0 commit comments

Comments
 (0)