From 42c5633bf648fcc78004a78cdde48b194b16bac3 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 7 Jul 2022 10:28:28 +0100 Subject: [PATCH] Improve `tqdm.contrib.logging` context managers (#8251) --- stubs/tqdm/tqdm/contrib/logging.pyi | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/stubs/tqdm/tqdm/contrib/logging.pyi b/stubs/tqdm/tqdm/contrib/logging.pyi index b7551e10c..f88587879 100644 --- a/stubs/tqdm/tqdm/contrib/logging.pyi +++ b/stubs/tqdm/tqdm/contrib/logging.pyi @@ -1,10 +1,19 @@ import logging -from collections.abc import Iterator, Sequence -from typing import Any +from _typeshed import Incomplete +from collections.abc import Callable, Sequence +from contextlib import _GeneratorContextManager +from typing import Any, TypeVar, overload from ..std import tqdm as std_tqdm +_TqdmT = TypeVar("_TqdmT", bound=std_tqdm[Any]) + def logging_redirect_tqdm( loggers: Sequence[logging.Logger] | None = ..., tqdm_class: type[std_tqdm[Any]] = ... -) -> Iterator[None]: ... -def tqdm_logging_redirect(*args, **kwargs) -> Iterator[None]: ... +) -> _GeneratorContextManager[None]: ... + +# TODO type *args, **kwargs here more precisely +@overload +def tqdm_logging_redirect(*args, tqdm_class: Callable[..., _TqdmT], **kwargs) -> _GeneratorContextManager[_TqdmT]: ... +@overload +def tqdm_logging_redirect(*args, **kwargs) -> _GeneratorContextManager[std_tqdm[Incomplete]]: ...