From 1255adbdb5a84d7b7a920e2531c04957ee30a17b Mon Sep 17 00:00:00 2001 From: Matthew Bradbury Date: Fri, 3 Jan 2025 12:52:10 +0000 Subject: [PATCH 1/2] tqdm: Improve wrapattr --- stubs/tqdm/tqdm/std.pyi | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/stubs/tqdm/tqdm/std.pyi b/stubs/tqdm/tqdm/std.pyi index 297b01784d10..bc43cbf3078f 100644 --- a/stubs/tqdm/tqdm/std.pyi +++ b/stubs/tqdm/tqdm/std.pyi @@ -1,5 +1,5 @@ import contextlib -from _typeshed import Incomplete, SupportsWrite +from _typeshed import Incomplete, SupportsRead, SupportsWrite from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping from types import TracebackType from typing import Any, ClassVar, Generic, Literal, NoReturn, TypeVar, overload @@ -30,6 +30,7 @@ class TqdmDeprecationWarning(TqdmWarning, DeprecationWarning): ... class TqdmMonitorWarning(TqdmWarning, RuntimeWarning): ... _T = TypeVar("_T") +_U = TypeVar("_U") class tqdm(Comparable, Generic[_T]): monitor_interval: ClassVar[int] @@ -222,10 +223,26 @@ class tqdm(Comparable, Generic[_T]): @property def format_dict(self) -> MutableMapping[str, Any]: ... def display(self, msg: str | None = None, pos: int | None = None) -> None: ... + @overload + @classmethod + def wrapattr( + cls, + stream: SupportsRead[_U], + method: Literal["read"], + total: float | None = None, + bytes: bool = True, + **tqdm_kwargs: Incomplete, + ) -> contextlib._GeneratorContextManager[SupportsRead[_U]]: ... + @overload @classmethod def wrapattr( - cls, stream, method: Literal["read", "write"], total: float | None = None, bytes: bool | None = True, **tqdm_kwargs - ) -> contextlib._GeneratorContextManager[Incomplete]: ... + cls, + stream: SupportsWrite[_U], + method: Literal["write"], + total: float | None = None, + bytes: bool = True, + **tqdm_kwargs: Incomplete, + ) -> contextlib._GeneratorContextManager[SupportsWrite[_U]]: ... @overload def trange( From f87386ac2560e71f1c873dc251de89b8206b194f Mon Sep 17 00:00:00 2001 From: Matthew Bradbury Date: Fri, 3 Jan 2025 13:23:23 +0000 Subject: [PATCH 2/2] Remove Incomplete from tqdm_kwargs --- stubs/tqdm/tqdm/std.pyi | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/stubs/tqdm/tqdm/std.pyi b/stubs/tqdm/tqdm/std.pyi index bc43cbf3078f..8ffbb0eaa60e 100644 --- a/stubs/tqdm/tqdm/std.pyi +++ b/stubs/tqdm/tqdm/std.pyi @@ -226,22 +226,12 @@ class tqdm(Comparable, Generic[_T]): @overload @classmethod def wrapattr( - cls, - stream: SupportsRead[_U], - method: Literal["read"], - total: float | None = None, - bytes: bool = True, - **tqdm_kwargs: Incomplete, + cls, stream: SupportsRead[_U], method: Literal["read"], total: float | None = None, bytes: bool = True, **tqdm_kwargs ) -> contextlib._GeneratorContextManager[SupportsRead[_U]]: ... @overload @classmethod def wrapattr( - cls, - stream: SupportsWrite[_U], - method: Literal["write"], - total: float | None = None, - bytes: bool = True, - **tqdm_kwargs: Incomplete, + cls, stream: SupportsWrite[_U], method: Literal["write"], total: float | None = None, bytes: bool = True, **tqdm_kwargs ) -> contextlib._GeneratorContextManager[SupportsWrite[_U]]: ... @overload