diff --git a/stubs/tqdm/METADATA.toml b/stubs/tqdm/METADATA.toml index 8b46cd5d48e9..911213ce5f75 100644 --- a/stubs/tqdm/METADATA.toml +++ b/stubs/tqdm/METADATA.toml @@ -1,4 +1,4 @@ -version = "4.69.*" +version = "4.70.*" upstream-repository = "https://github.com/tqdm/tqdm" optional-dependencies = ["types-requests", "types-tensorflow"] diff --git a/stubs/tqdm/tqdm/contrib/concurrent.pyi b/stubs/tqdm/tqdm/contrib/concurrent.pyi index 982a359416cd..0d2db089baa9 100644 --- a/stubs/tqdm/tqdm/contrib/concurrent.pyi +++ b/stubs/tqdm/tqdm/contrib/concurrent.pyi @@ -1,11 +1,14 @@ +import sys from _typeshed import SupportsWrite -from collections.abc import Callable, Iterable, Mapping +from collections.abc import Callable, Generator, Iterable, Mapping +from contextlib import contextmanager +from multiprocessing.context import BaseContext from typing import Any, TypedDict, TypeVar, overload, type_check_only from typing_extensions import Unpack from ..std import tqdm -__all__ = ["thread_map", "process_map"] +__all__ = ["thread_map", "process_map", "interpreter_map"] _R = TypeVar("_R") _T1 = TypeVar("_T1") @@ -15,12 +18,11 @@ _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") @type_check_only -class _TqdmKwargs(TypedDict, total=False): +class _TqdmCommonKwargs(TypedDict, total=False): # Concurrent-specific parameters tqdm_class: type[tqdm[object]] max_workers: int | None chunksize: int - lock_name: str # Standard tqdm parameters desc: str | None total: float | None @@ -47,11 +49,34 @@ class _TqdmKwargs(TypedDict, total=False): colour: str | None delay: float | None +# TODO: refactor this, when `TypedDict` will support conditional fields +if sys.version_info >= (3, 14): + @type_check_only + class _TqdmKwargs(_TqdmCommonKwargs): + buffersize: int | None + +else: + _TqdmKwargs = _TqdmCommonKwargs + +@type_check_only +class _TqdmProcessKwargs(_TqdmKwargs): + mp_context: BaseContext | None + max_tasks_per_child: int | None + +@type_check_only +class _TqdmThreadKwargs(_TqdmKwargs): + thread_name_prefix: str | None + # Not techically for threading, but just a signature difference: + lock_name: str + +@contextmanager +def ensure_lock(tqdm_class: type[tqdm[object]], lock_name: str = "", lock=None) -> Generator[None]: ... + @overload -def thread_map(fn: Callable[[_T1], _R], iter1: Iterable[_T1], **tqdm_kwargs: Unpack[_TqdmKwargs]) -> list[_R]: ... +def thread_map(fn: Callable[[_T1], _R], iter1: Iterable[_T1], **tqdm_kwargs: Unpack[_TqdmThreadKwargs]) -> list[_R]: ... @overload def thread_map( - fn: Callable[[_T1, _T2], _R], iter1: Iterable[_T1], iter2: Iterable[_T2], /, **tqdm_kwargs: Unpack[_TqdmKwargs] + fn: Callable[[_T1, _T2], _R], iter1: Iterable[_T1], iter2: Iterable[_T2], /, **tqdm_kwargs: Unpack[_TqdmThreadKwargs] ) -> list[_R]: ... @overload def thread_map( @@ -59,7 +84,7 @@ def thread_map( iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - **tqdm_kwargs: Unpack[_TqdmKwargs], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], ) -> list[_R]: ... @overload def thread_map( @@ -68,7 +93,7 @@ def thread_map( iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], - **tqdm_kwargs: Unpack[_TqdmKwargs], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], ) -> list[_R]: ... @overload def thread_map( @@ -78,7 +103,7 @@ def thread_map( iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5], - **tqdm_kwargs: Unpack[_TqdmKwargs], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], ) -> list[_R]: ... @overload def thread_map( @@ -90,14 +115,21 @@ def thread_map( iter5: Iterable[Any], iter6: Iterable[Any], *iterables: Iterable[Any], - **tqdm_kwargs: Unpack[_TqdmKwargs], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], ) -> list[_R]: ... @overload -def process_map(fn: Callable[[_T1], _R], iter1: Iterable[_T1], **tqdm_kwargs: Unpack[_TqdmKwargs]) -> list[_R]: ... +def process_map( + fn: Callable[[_T1], _R], iter1: Iterable[_T1], *, lock_name: str = "mp_lock", **tqdm_kwargs: Unpack[_TqdmProcessKwargs] +) -> list[_R]: ... @overload def process_map( - fn: Callable[[_T1, _T2], _R], iter1: Iterable[_T1], iter2: Iterable[_T2], **tqdm_kwargs: Unpack[_TqdmKwargs] + fn: Callable[[_T1, _T2], _R], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + *, + lock_name: str = "mp_lock", + **tqdm_kwargs: Unpack[_TqdmProcessKwargs], ) -> list[_R]: ... @overload def process_map( @@ -105,7 +137,9 @@ def process_map( iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], - **tqdm_kwargs: Unpack[_TqdmKwargs], + *, + lock_name: str = "mp_lock", + **tqdm_kwargs: Unpack[_TqdmProcessKwargs], ) -> list[_R]: ... @overload def process_map( @@ -114,7 +148,9 @@ def process_map( iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], - **tqdm_kwargs: Unpack[_TqdmKwargs], + *, + lock_name: str = "mp_lock", + **tqdm_kwargs: Unpack[_TqdmProcessKwargs], ) -> list[_R]: ... @overload def process_map( @@ -124,7 +160,9 @@ def process_map( iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5], - **tqdm_kwargs: Unpack[_TqdmKwargs], + *, + lock_name: str = "mp_lock", + **tqdm_kwargs: Unpack[_TqdmProcessKwargs], ) -> list[_R]: ... @overload def process_map( @@ -136,5 +174,52 @@ def process_map( iter5: Iterable[Any], iter6: Iterable[Any], *iterables: Iterable[Any], - **tqdm_kwargs: Unpack[_TqdmKwargs], + lock_name: str = "mp_lock", + **tqdm_kwargs: Unpack[_TqdmProcessKwargs], +) -> list[_R]: ... + +@overload +def interpreter_map(fn: Callable[[_T1], _R], iter1: Iterable[_T1], **tqdm_kwargs: Unpack[_TqdmThreadKwargs]) -> list[_R]: ... +@overload +def interpreter_map( + fn: Callable[[_T1, _T2], _R], iter1: Iterable[_T1], iter2: Iterable[_T2], /, **tqdm_kwargs: Unpack[_TqdmThreadKwargs] +) -> list[_R]: ... +@overload +def interpreter_map( + fn: Callable[[_T1, _T2, _T3], _R], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], +) -> list[_R]: ... +@overload +def interpreter_map( + fn: Callable[[_T1, _T2, _T3, _T4], _R], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], +) -> list[_R]: ... +@overload +def interpreter_map( + fn: Callable[[_T1, _T2, _T3, _T4, _T5], _R], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], +) -> list[_R]: ... +@overload +def interpreter_map( + fn: Callable[..., _R], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any], + **tqdm_kwargs: Unpack[_TqdmThreadKwargs], ) -> list[_R]: ...