From 8607fa308863496cf7073024e76a622e042bbc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 24 Mar 2021 16:29:59 +0100 Subject: [PATCH 1/2] typing: unify type hints for `total` keyword arguments in rich.progress --- rich/progress.py | 20 ++++++++++---------- rich/progress_bar.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index 8a246ee5..6b05456d 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -83,7 +83,7 @@ class _TrackThread(Thread): 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, @@ -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. @@ -650,7 +650,7 @@ class Progress(JupyterMixin): 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, @@ -659,7 +659,7 @@ class Progress(JupyterMixin): 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. @@ -670,7 +670,7 @@ class Progress(JupyterMixin): 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'" @@ -729,7 +729,7 @@ class Progress(JupyterMixin): self, task_id: TaskID, *, - total: float = None, + total: Optional[float] = None, completed: float = None, advance: float = None, description: str = None, @@ -789,7 +789,7 @@ class Progress(JupyterMixin): 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, @@ -800,7 +800,7 @@ class Progress(JupyterMixin): 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. """ @@ -904,7 +904,7 @@ class Progress(JupyterMixin): self, description: str, start: bool = True, - total: int = 100, + total: float = 100.0, completed: int = 0, visible: bool = True, **fields: Any, @@ -915,7 +915,7 @@ class Progress(JupyterMixin): 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. diff --git a/rich/progress_bar.py b/rich/progress_bar.py index 63b0168c..d25c5095 100644 --- a/rich/progress_bar.py +++ b/rich/progress_bar.py @@ -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, From 4eac117be0fb04990dadc851292870fafd6e1488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 24 Mar 2021 16:39:15 +0100 Subject: [PATCH 2/2] update changelog and contributors --- CHANGELOG.md | 6 ++++++ CONTRIBUTORS.md | 1 + 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f3deac..8b9b48e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Made type annotations consistent for various `total` keyword arguments in `rich.progress` and rich.`progress_bar` + ## [9.13.0] - 2021-03-06 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c6db7bf9..7f318fee 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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)