Skip to content

Commit

Permalink
Merge pull request #1131 from neutrinoceros/type_annotations_progress…
Browse files Browse the repository at this point in the history
…_total

typing: unify type hints for `total` keyword arguments in rich.progress
  • Loading branch information
willmcgugan committed Mar 25, 2021
2 parents 95016f4 + e08a838 commit d1f819a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed table style taking precedence over row style https://github.com/willmcgugan/rich/issues/1129
- Fixed incorrect measurement of Text with new lines and whitespace https://github.com/willmcgugan/rich/issues/1133
- Made type annotations consistent for various `total` keyword arguments in `rich.progress` and rich.`progress_bar`


## [9.13.0] - 2021-03-06

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -10,3 +10,4 @@ The following people have contributed to the development of Rich:
- [Alexander Mancevice](https://github.com/amancevice)
- [Will McGugan](https://github.com/willmcgugan)
- [Nathan Page](https://github.com/nathanrpage97)
- [Clément Robert](https://github.com/neutrinoceros)
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 d1f819a

Please sign in to comment.