diff --git a/CHANGELOG.md b/CHANGELOG.md index 70652e14..4549ab1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rebuilt SVG export to create a simpler SVG that is more portable - 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 diff --git a/rich/progress.py b/rich/progress.py index ca52c4b9..c8eeefbf 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) -> 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