Skip to content

Commit 1965b20

Browse files
authored
[tqdm] Add thread_map and process_map type hints (#15460)
1 parent b8b4b69 commit 1965b20

File tree

1 file changed

+137
-2
lines changed

1 file changed

+137
-2
lines changed
Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,139 @@
1+
from _typeshed import SupportsWrite
2+
from collections.abc import Callable, Iterable, Mapping
3+
from typing import Any, TypedDict, TypeVar, overload, type_check_only
4+
from typing_extensions import Unpack
5+
6+
from ..std import tqdm
7+
18
__all__ = ["thread_map", "process_map"]
29

3-
def thread_map(fn, *iterables, **tqdm_kwargs): ...
4-
def process_map(fn, *iterables, **tqdm_kwargs): ...
10+
_R = TypeVar("_R")
11+
_T1 = TypeVar("_T1")
12+
_T2 = TypeVar("_T2")
13+
_T3 = TypeVar("_T3")
14+
_T4 = TypeVar("_T4")
15+
_T5 = TypeVar("_T5")
16+
17+
@type_check_only
18+
class _TqdmKwargs(TypedDict, total=False):
19+
# Concurrent-specific parameters
20+
tqdm_class: type[tqdm[object]]
21+
max_workers: int | None
22+
chunksize: int
23+
lock_name: str
24+
# Standard tqdm parameters
25+
desc: str | None
26+
total: float | None
27+
leave: bool | None
28+
file: SupportsWrite[str] | None
29+
ncols: int | None
30+
mininterval: float
31+
maxinterval: float
32+
miniters: float | None
33+
ascii: bool | str | None
34+
disable: bool | None
35+
unit: str
36+
unit_scale: bool | float
37+
dynamic_ncols: bool
38+
smoothing: float
39+
bar_format: str | None
40+
initial: float
41+
position: int | None
42+
postfix: Mapping[str, object] | str | None
43+
unit_divisor: float
44+
write_bytes: bool | None
45+
lock_args: tuple[bool | None, float | None] | tuple[bool | None] | None
46+
nrows: int | None
47+
colour: str | None
48+
delay: float | None
49+
50+
@overload
51+
def thread_map(fn: Callable[[_T1], _R], iter1: Iterable[_T1], **tqdm_kwargs: Unpack[_TqdmKwargs]) -> list[_R]: ...
52+
@overload
53+
def thread_map(
54+
fn: Callable[[_T1, _T2], _R], iter1: Iterable[_T1], iter2: Iterable[_T2], /, **tqdm_kwargs: Unpack[_TqdmKwargs]
55+
) -> list[_R]: ...
56+
@overload
57+
def thread_map(
58+
fn: Callable[[_T1, _T2, _T3], _R],
59+
iter1: Iterable[_T1],
60+
iter2: Iterable[_T2],
61+
iter3: Iterable[_T3],
62+
**tqdm_kwargs: Unpack[_TqdmKwargs],
63+
) -> list[_R]: ...
64+
@overload
65+
def thread_map(
66+
fn: Callable[[_T1, _T2, _T3, _T4], _R],
67+
iter1: Iterable[_T1],
68+
iter2: Iterable[_T2],
69+
iter3: Iterable[_T3],
70+
iter4: Iterable[_T4],
71+
**tqdm_kwargs: Unpack[_TqdmKwargs],
72+
) -> list[_R]: ...
73+
@overload
74+
def thread_map(
75+
fn: Callable[[_T1, _T2, _T3, _T4, _T5], _R],
76+
iter1: Iterable[_T1],
77+
iter2: Iterable[_T2],
78+
iter3: Iterable[_T3],
79+
iter4: Iterable[_T4],
80+
iter5: Iterable[_T5],
81+
**tqdm_kwargs: Unpack[_TqdmKwargs],
82+
) -> list[_R]: ...
83+
@overload
84+
def thread_map(
85+
fn: Callable[..., _R],
86+
iter1: Iterable[Any],
87+
iter2: Iterable[Any],
88+
iter3: Iterable[Any],
89+
iter4: Iterable[Any],
90+
iter5: Iterable[Any],
91+
iter6: Iterable[Any],
92+
*iterables: Iterable[Any],
93+
**tqdm_kwargs: Unpack[_TqdmKwargs],
94+
) -> list[_R]: ...
95+
@overload
96+
def process_map(fn: Callable[[_T1], _R], iter1: Iterable[_T1], **tqdm_kwargs: Unpack[_TqdmKwargs]) -> list[_R]: ...
97+
@overload
98+
def process_map(
99+
fn: Callable[[_T1, _T2], _R], iter1: Iterable[_T1], iter2: Iterable[_T2], **tqdm_kwargs: Unpack[_TqdmKwargs]
100+
) -> list[_R]: ...
101+
@overload
102+
def process_map(
103+
fn: Callable[[_T1, _T2, _T3], _R],
104+
iter1: Iterable[_T1],
105+
iter2: Iterable[_T2],
106+
iter3: Iterable[_T3],
107+
**tqdm_kwargs: Unpack[_TqdmKwargs],
108+
) -> list[_R]: ...
109+
@overload
110+
def process_map(
111+
fn: Callable[[_T1, _T2, _T3, _T4], _R],
112+
iter1: Iterable[_T1],
113+
iter2: Iterable[_T2],
114+
iter3: Iterable[_T3],
115+
iter4: Iterable[_T4],
116+
**tqdm_kwargs: Unpack[_TqdmKwargs],
117+
) -> list[_R]: ...
118+
@overload
119+
def process_map(
120+
fn: Callable[[_T1, _T2, _T3, _T4, _T5], _R],
121+
iter1: Iterable[_T1],
122+
iter2: Iterable[_T2],
123+
iter3: Iterable[_T3],
124+
iter4: Iterable[_T4],
125+
iter5: Iterable[_T5],
126+
**tqdm_kwargs: Unpack[_TqdmKwargs],
127+
) -> list[_R]: ...
128+
@overload
129+
def process_map(
130+
fn: Callable[..., _R],
131+
iter1: Iterable[Any],
132+
iter2: Iterable[Any],
133+
iter3: Iterable[Any],
134+
iter4: Iterable[Any],
135+
iter5: Iterable[Any],
136+
iter6: Iterable[Any],
137+
*iterables: Iterable[Any],
138+
**tqdm_kwargs: Unpack[_TqdmKwargs],
139+
) -> list[_R]: ...

0 commit comments

Comments
 (0)