Merge pull request #2254 from althonos/master

Forward the internal handle name wrapped in `rich.progress._Reader`
This commit is contained in:
Will McGugan 2022-06-14 09:18:32 +01:00 committed by GitHub
commit 7870603929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -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