From 5e8da24c4eb13721e541da093688c9610f541e7f Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Thu, 16 Dec 2021 15:02:08 +0100 Subject: [PATCH] Fix additional typing issues in `rich.progress` --- CHANGELOG.md | 7 +++++++ CONTRIBUTORS.md | 1 + rich/progress.py | 12 ++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ffa527..79b01a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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 + +### Added + +- Progress.read method to track the progress while reading from a file https://github.com/willmcgugan/rich/pull/1759 + + ## [12.0.0] - 2022-03-10 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 140f77f4..f3c0237a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -18,6 +18,7 @@ The following people have contributed to the development of Rich: - [Finn Hughes](https://github.com/finnhughes) - [Josh Karpel](https://github.com/JoshKarpel) - [Andrew Kettmann](https://github.com/akettmann) +- [Martin Larralde](https://github.com/althonos) - [Hedy Li](https://github.com/hedythedev) - [Alexander Mancevice](https://github.com/amancevice) - [Will McGugan](https://github.com/willmcgugan) diff --git a/rich/progress.py b/rich/progress.py index 1bda66ca..b22568e6 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -171,7 +171,7 @@ class _Reader(RawIOBase, BinaryIO): self.close_handle = close_handle self._closed = False - def __enter__(self): + def __enter__(self) -> "_Reader": self.handle.__enter__() return self @@ -218,7 +218,7 @@ class _Reader(RawIOBase, BinaryIO): def readall(self) -> bytes: block = self.handle.readall() # type: ignore self.progress.advance(self.task, advance=len(block)) - return block + return block # type: ignore def readinto(self, b: Union[bytearray, memoryview, mmap]): # type: ignore n = self.handle.readinto(b) # type: ignore @@ -240,7 +240,7 @@ class _Reader(RawIOBase, BinaryIO): self.handle.close() self._closed = True - def seek(self, offset: int, whence: int = 0): + def seek(self, offset: int, whence: int = 0) -> int: pos = self.handle.seek(offset, whence) self.progress.update(self.task, completed=pos) return pos @@ -274,7 +274,7 @@ class _ReadContext(ContextManager[BinaryIO]): def read( - file: Union[str, PathLike, BinaryIO], + file: Union[str, PathLike[str], BinaryIO], description: str = "Reading...", total: Optional[int] = None, auto_refresh: bool = True, @@ -986,7 +986,7 @@ class Progress(JupyterMixin): def read( self, - file: Union[str, PathLike, BinaryIO], + file: Union[str, PathLike[str], BinaryIO], total: Optional[int] = None, task_id: Optional[TaskID] = None, description: str = "Reading...", @@ -994,7 +994,7 @@ class Progress(JupyterMixin): """Track progress while reading from a binary file. Args: - file (Union[str, PathLike, BinaryIO]): The path to the file to read, or a file-like object in binary mode. + file (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode. total: (int, optional): Total number of bytes to read. Must be provided if reading from a file handle. Default for a path is os.stat(file).st_size. task_id: (TaskID): Task to track. Default is new task. description: (str, optional): Description of task, if new task is created.