Skip to content

Commit de98eb9

Browse files
Exported TargetFunction typing to _types
1 parent 316184d commit de98eb9

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/thread/_types.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
from typing import Any, Literal, Callable, Union
88

9+
10+
# Descriptive Types
11+
Data_In = Any
12+
Data_Out = Any
13+
Overflow_In = Any
14+
15+
16+
# Variable Types
917
ThreadStatus = Literal[
1018
'Idle',
1119
'Running',
@@ -16,8 +24,8 @@
1624
'Kill Scheduled',
1725
'Killed'
1826
]
19-
Data_In = Any
20-
Data_Out = Any
21-
Overflow_In = Any
2227

28+
29+
# Function types
2330
HookFunction = Callable[[Data_Out], Union[Any, None]]
31+
TargetFunction = Callable[..., Data_Out]

src/thread/thread.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class ParallelProcessing: ...
1919
from .utils.config import Settings
2020
from .utils.algorithm import chunk_split
2121

22-
from ._types import ThreadStatus, Data_In, Data_Out, Overflow_In, HookFunction
22+
from ._types import ThreadStatus, Data_In, Data_Out, Overflow_In, TargetFunction, HookFunction
2323
from typing import (
2424
Any, List,
25-
Callable, Union, Optional,
25+
Callable, Optional,
2626
Mapping, Sequence, Tuple
2727
)
2828

@@ -51,7 +51,7 @@ class Thread(threading.Thread):
5151

5252
def __init__(
5353
self,
54-
target: Callable[..., Data_Out],
54+
target: TargetFunction,
5555
args: Sequence[Data_In] = (),
5656
kwargs: Mapping[str, Data_In] = {},
5757
ignore_errors: Sequence[type[Exception]] = (),
@@ -100,7 +100,7 @@ def __init__(
100100
)
101101

102102

103-
def _wrap_target(self, target: Callable[..., Data_Out]) -> Callable[..., Data_Out]:
103+
def _wrap_target(self, target: TargetFunction) -> TargetFunction:
104104
"""Wraps the target function"""
105105
@wraps(target)
106106
def wrapper(*args: Any, **kwargs: Any) -> Any:
@@ -344,7 +344,7 @@ class ParallelProcessing:
344344

345345
def __init__(
346346
self,
347-
function: Callable[..., Data_Out],
347+
function: TargetFunction,
348348
dataset: Sequence[Data_In],
349349
max_threads: int = 8,
350350

@@ -385,7 +385,7 @@ def __init__(
385385

386386
def _wrap_function(
387387
self,
388-
function: Callable[..., Data_Out]
388+
function: TargetFunction
389389
) -> Callable[..., List[Data_Out]]:
390390
@wraps(function)
391391
def wrapper(index: int, data_chunk: Sequence[Data_In], *args: Any, **kwargs: Any) -> List[Data_Out]:

0 commit comments

Comments
 (0)