Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions stubs/tqdm/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
tqdm.contrib.discord

# Metaclass differs:
tqdm.rich.FractionColumn
tqdm.rich.RateColumn
# Shims
tqdm._rich_shims
141 changes: 141 additions & 0 deletions stubs/tqdm/tqdm/_rich_shims.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
from _typeshed import Incomplete
from abc import ABC, abstractmethod
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from typing import NamedTuple, Protocol, runtime_checkable
from typing_extensions import Literal, TypeAlias

# rich.text
Text: TypeAlias = str | Incomplete

# rich.align
VerticalAlignMethod: TypeAlias = Literal["top", "middle", "bottom"]

# rich.style
StyleType: TypeAlias = str | Incomplete

# rich.table

@dataclass
class Column(Protocol):
header: RenderableType
footer: RenderableType
header_style: StyleType
footer_style: StyleType
style: StyleType
justify: JustifyMethod
vertical: VerticalAlignMethod
overflow: OverflowMethod
width: int | None
min_width: int | None
max_width: int | None
ratio: int | None
no_wrap: bool
def copy(self) -> Column: ...
@property
def cells(self) -> Iterable[RenderableType]: ...
@property
def flexible(self) -> bool: ...

# rich.segment
Segment: TypeAlias = Incomplete

# region rich.console
HighlighterType: TypeAlias = Callable[[str | Text], Text]
JustifyMethod: TypeAlias = Literal["default", "left", "center", "right", "full"]
OverflowMethod: TypeAlias = Literal["fold", "crop", "ellipsis", "ignore"]
RenderResult: TypeAlias = Iterable[RenderableType | Segment]
Console: TypeAlias = Incomplete

class NoChange: ...

class ConsoleDimensions(NamedTuple):
width: int
height: int

@dataclass
class ConsoleOptions:
size: ConsoleDimensions
legacy_windows: bool
min_width: int
max_width: int
is_terminal: bool
encoding: str
max_height: int
justify: JustifyMethod | None
overflow: OverflowMethod | None
no_wrap: bool | None
highlight: bool | None
markup: bool | None
height: int | None
@property
def ascii_only(self) -> bool: ...
def copy(self) -> ConsoleOptions: ...
def update(
self,
*,
width: int | NoChange,
min_width: int | NoChange,
max_width: int | NoChange,
justify: JustifyMethod | None | NoChange,
overflow: OverflowMethod | None | NoChange,
no_wrap: bool | None | NoChange,
highlight: bool | None | NoChange,
markup: bool | None | NoChange,
height: int | None | NoChange,
) -> ConsoleOptions: ...
def update_width(self, width: int) -> ConsoleOptions: ...
def update_height(self, height: int) -> ConsoleOptions: ...
def reset_height(self) -> ConsoleOptions: ...
def update_dimensions(self, width: int, height: int) -> ConsoleOptions: ...

@runtime_checkable
class RichCast(Protocol):
def __rich__(self) -> ConsoleRenderable | RichCast | str: ...

@runtime_checkable
class ConsoleRenderable(Protocol):
def __rich_console__(self, console: Console, options: ConsoleOptions) -> RenderResult: ...

RenderableType: TypeAlias = ConsoleRenderable | RichCast | str

# endregion

# region rich.progress.Task
@dataclass
class Task(Protocol):
id: int
description: str
total: float | None
completed: float
finished_time: float | None
visible: bool
fields: dict[str, Incomplete]
start_time: float | None
stop_time: float | None
finished_speed: float | None
def get_time(self) -> float: ...
@property
def started(self) -> bool: ...
@property
def remaining(self) -> float | None: ...
@property
def elapsed(self) -> float | None: ...
@property
def finished(self) -> bool: ...
@property
def percentage(self) -> float: ...
@property
def speed(self) -> float | None: ...
@property
def time_remaining(self) -> float | None: ...

class ProgressColumn(ABC):
max_refresh: float | None
def __init__(self, table_column: Column | None = ...) -> None: ...
def get_table_column(self) -> Column: ...
def __call__(self, task: Task) -> RenderableType: ...
@abstractmethod
def render(self, task: Task) -> RenderableType: ...

# endregion
22 changes: 18 additions & 4 deletions stubs/tqdm/tqdm/dask.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
from _typeshed import Incomplete
from typing import Any
from typing_extensions import TypeAlias
from _typeshed import Incomplete, Self
from collections.abc import Callable
from typing import ClassVar

__all__ = ["TqdmCallback"]

_Callback: TypeAlias = Any # Actually dask.callbacks.Callback
# dask.callbacks.Callback
class _Callback:
active: ClassVar[set[tuple[Callable[..., Incomplete] | None, ...]]]
def __init__(
self,
start: Incomplete | None,
start_state: Incomplete | None,
pretask: Incomplete | None,
posttask: Incomplete | None,
finish: Incomplete | None,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args) -> None: ...
def register(self) -> None: ...
def unregister(self) -> None: ...

class TqdmCallback(_Callback):
tqdm_class: type[Incomplete]
Expand Down
27 changes: 24 additions & 3 deletions stubs/tqdm/tqdm/keras.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
from _typeshed import Incomplete
from typing import Any
from typing_extensions import TypeAlias

__all__ = ["TqdmCallback"]

_Callback: TypeAlias = Any # Actually tensorflow.keras.callbacks.Callback
# keras.callbacks.Callback
Comment thread
AlexWaygood marked this conversation as resolved.
class _Callback:
validation_data: Incomplete | None
model: Incomplete | None
params: Incomplete
def __init__(self) -> None: ...
def set_params(self, params) -> None: ...
def set_model(self, model) -> None: ...
def on_batch_begin(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_batch_end(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_epoch_begin(self, epoch, logs: Incomplete | None = ...) -> None: ...
def on_epoch_end(self, epoch, logs: Incomplete | None = ...) -> None: ...
def on_train_batch_begin(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_train_batch_end(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_test_batch_begin(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_test_batch_end(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_predict_batch_begin(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_predict_batch_end(self, batch, logs: Incomplete | None = ...) -> None: ...
def on_train_begin(self, logs: Incomplete | None = ...) -> None: ...
def on_train_end(self, logs: Incomplete | None = ...) -> None: ...
def on_test_begin(self, logs: Incomplete | None = ...) -> None: ...
def on_test_end(self, logs: Incomplete | None = ...) -> None: ...
def on_predict_begin(self, logs: Incomplete | None = ...) -> None: ...
def on_predict_end(self, logs: Incomplete | None = ...) -> None: ...

class TqdmCallback(_Callback):
@staticmethod
Expand Down
10 changes: 4 additions & 6 deletions stubs/tqdm/tqdm/rich.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from _typeshed import Incomplete, SupportsWrite
from collections.abc import Iterable, Mapping
from typing import Any, Generic, NoReturn, TypeVar, overload
from typing_extensions import TypeAlias
from typing import Generic, NoReturn, TypeVar, overload

from ._rich_shims import ProgressColumn
from .std import tqdm as std_tqdm

__all__ = ["tqdm_rich", "trrange", "tqdm", "trange"]

_ProgressColumn: TypeAlias = Any # Actually rich.progress.ProgressColumn

class FractionColumn(_ProgressColumn):
class FractionColumn(ProgressColumn):
unit_scale: bool
unit_divisor: int

def __init__(self, unit_scale: bool = ..., unit_divisor: int = ...) -> None: ...
def render(self, task): ...

class RateColumn(_ProgressColumn):
class RateColumn(ProgressColumn):
unit: str
unit_scale: bool
unit_divisor: int
Expand Down