Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward the internal handle name wrapped in rich.progress._Reader #2254

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions rich/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def fileno(self) -> int:
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()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down