From ca94962307093e2bdc9861c9319d105fda0f0b98 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Thu, 5 May 2022 12:25:32 +0200 Subject: [PATCH 1/3] Forward the internal handle name wrapped in `rich.progress._Reader` --- rich/progress.py | 4 ++++ tests/test_progress.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/rich/progress.py b/rich/progress.py index ca52c4b9..9acd795f 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -216,6 +216,10 @@ class _Reader(RawIOBase, BinaryIO): def isatty(self) -> bool: return self.handle.isatty() + @property + def name(self) -> Optional[str]: + return self.handle.name + def readable(self) -> bool: return self.handle.readable() diff --git a/tests/test_progress.py b/tests/test_progress.py index 8a90ad80..792ee636 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -600,6 +600,7 @@ def test_open_text_mode() -> None: try: with rich.progress.open(filename, "r") as f: assert f.read() == "Hello, World!" + assert f.name == filename assert f.closed finally: os.remove(filename) @@ -613,6 +614,7 @@ def test_wrap_file() -> None: with open(filename, "rb") as file: with rich.progress.wrap_file(file, total=total) as f: assert f.read() == b"Hello, World!" + assert f.name == filename assert f.closed assert not f.handle.closed assert not file.closed From 4cbd5c1479ad2ee51eeed9d15d5c66e2775546d6 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Thu, 5 May 2022 12:31:58 +0200 Subject: [PATCH 2/3] Update `CHANGELOG.md` with change from #2254 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb65a531..8df3c65b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change SVG export to create a simpler SVG - Fix render_lines crash when render height was negative https://github.com/Textualize/rich/pull/2246 +- Make objects from `rich.progress.open` forward the name of the internal handle https://github.com/Textualize/rich/pull/2254 ### Added From b248bf86607035cb0c8eec47384e28ceee36b5c7 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Thu, 5 May 2022 12:38:28 +0200 Subject: [PATCH 3/3] Fix type annotations of `_Reader.name` --- rich/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/progress.py b/rich/progress.py index 9acd795f..c8eeefbf 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -217,7 +217,7 @@ class _Reader(RawIOBase, BinaryIO): return self.handle.isatty() @property - def name(self) -> Optional[str]: + def name(self) -> str: return self.handle.name def readable(self) -> bool: