Skip to content

Commit 3658ba8

Browse files
authored
tqdm: Improve wrapattr (#13361)
1 parent f090e37 commit 3658ba8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

stubs/tqdm/tqdm/std.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import contextlib
2-
from _typeshed import Incomplete, SupportsWrite
2+
from _typeshed import Incomplete, SupportsRead, SupportsWrite
33
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping
44
from types import TracebackType
55
from typing import Any, ClassVar, Generic, Literal, NoReturn, TypeVar, overload
@@ -30,6 +30,7 @@ class TqdmDeprecationWarning(TqdmWarning, DeprecationWarning): ...
3030
class TqdmMonitorWarning(TqdmWarning, RuntimeWarning): ...
3131

3232
_T = TypeVar("_T")
33+
_U = TypeVar("_U")
3334

3435
class tqdm(Comparable, Generic[_T]):
3536
monitor_interval: ClassVar[int]
@@ -222,10 +223,16 @@ class tqdm(Comparable, Generic[_T]):
222223
@property
223224
def format_dict(self) -> MutableMapping[str, Any]: ...
224225
def display(self, msg: str | None = None, pos: int | None = None) -> None: ...
226+
@overload
227+
@classmethod
228+
def wrapattr(
229+
cls, stream: SupportsRead[_U], method: Literal["read"], total: float | None = None, bytes: bool = True, **tqdm_kwargs
230+
) -> contextlib._GeneratorContextManager[SupportsRead[_U]]: ...
231+
@overload
225232
@classmethod
226233
def wrapattr(
227-
cls, stream, method: Literal["read", "write"], total: float | None = None, bytes: bool | None = True, **tqdm_kwargs
228-
) -> contextlib._GeneratorContextManager[Incomplete]: ...
234+
cls, stream: SupportsWrite[_U], method: Literal["write"], total: float | None = None, bytes: bool = True, **tqdm_kwargs
235+
) -> contextlib._GeneratorContextManager[SupportsWrite[_U]]: ...
229236

230237
@overload
231238
def trange(

0 commit comments

Comments
 (0)