Skip to content

Commit

Permalink
typing: unify type hints for total keyword arguments in rich.progress
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Mar 24, 2021
1 parent 5d716be commit 8607fa3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions rich/progress.py
Expand Up @@ -83,7 +83,7 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
def track(
sequence: Union[Sequence[ProgressType], Iterable[ProgressType]],
description="Working...",
total: int = None,
total: Optional[float] = None,
auto_refresh=True,
console: Optional[Console] = None,
transient: bool = False,
Expand All @@ -101,7 +101,7 @@ def track(
Args:
sequence (Iterable[ProgressType]): A sequence (must support "len") you wish to iterate over.
description (str, optional): Description of task show next to progress bar. Defaults to "Working".
total: (int, optional): Total number of steps. Default is len(sequence).
total: (float, optional): Total number of steps. Default is len(sequence).
auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
transient: (bool, optional): Clear the progress on exit. Defaults to False.
console (Console, optional): Console to write to. Default creates internal Console instance.
Expand Down Expand Up @@ -650,7 +650,7 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
def track(
self,
sequence: Union[Iterable[ProgressType], Sequence[ProgressType]],
total: int = None,
total: Optional[float] = None,
task_id: Optional[TaskID] = None,
description="Working...",
update_period: float = 0.1,
Expand All @@ -659,7 +659,7 @@ def track(
Args:
sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress.
total: (int, optional): Total number of steps. Default is len(sequence).
total: (float, optional): Total number of steps. Default is len(sequence).
task_id: (TaskID): Task to track. Default is new task.
description: (str, optional): Description of task, if new task is created.
update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
Expand All @@ -670,7 +670,7 @@ def track(

if total is None:
if isinstance(sequence, Sized):
task_total = len(sequence)
task_total = float(len(sequence))
else:
raise ValueError(
f"unable to get size of {sequence!r}, please specify 'total'"
Expand Down Expand Up @@ -729,7 +729,7 @@ def update(
self,
task_id: TaskID,
*,
total: float = None,
total: Optional[float] = None,
completed: float = None,
advance: float = None,
description: str = None,
Expand Down Expand Up @@ -789,7 +789,7 @@ def reset(
task_id: TaskID,
*,
start: bool = True,
total: Optional[int] = None,
total: Optional[float] = None,
completed: int = 0,
visible: Optional[bool] = None,
description: Optional[str] = None,
Expand All @@ -800,7 +800,7 @@ def reset(
Args:
task_id (TaskID): ID of task.
start (bool, optional): Start the task after reset. Defaults to True.
total (int, optional): New total steps in task, or None to use current total. Defaults to None.
total (float, optional): New total steps in task, or None to use current total. Defaults to None.
completed (int, optional): Number of steps completed. Defaults to 0.
**fields (str): Additional data fields required for rendering.
"""
Expand Down Expand Up @@ -904,7 +904,7 @@ def add_task(
self,
description: str,
start: bool = True,
total: int = 100,
total: float = 100.0,
completed: int = 0,
visible: bool = True,
**fields: Any,
Expand All @@ -915,7 +915,7 @@ def add_task(
description (str): A description of the task.
start (bool, optional): Start the task immediately (to calculate elapsed time). If set to False,
you will need to call `start` manually. Defaults to True.
total (int, optional): Number of total steps in the progress if know. Defaults to 100.
total (float, optional): Number of total steps in the progress if know. Defaults to 100.
completed (int, optional): Number of steps completed so far.. Defaults to 0.
visible (bool, optional): Enable display of the task. Defaults to True.
**fields (str): Additional data fields required for rendering.
Expand Down
2 changes: 1 addition & 1 deletion rich/progress_bar.py
Expand Up @@ -32,7 +32,7 @@ class ProgressBar(JupyterMixin):

def __init__(
self,
total: float = 100,
total: float = 100.0,
completed: float = 0,
width: int = None,
pulse: bool = False,
Expand Down

0 comments on commit 8607fa3

Please sign in to comment.