Merge pull request #3905 from TomerYogev/extra-blank-line-on-disabled-progress

Update progress.py
This commit is contained in:
Will McGugan 2026-01-23 10:36:23 +00:00 committed by GitHub
commit fe55a131c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 5 deletions

View File

@ -5,12 +5,12 @@ 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
## [Unreleased]
### Fixed
- IPython now respects when a `Console` instance is passed to `pretty.install` https://github.com/Textualize/rich/pull/3915
- Fixed extraneous blank line on non-interactive disabled `Progress` https://github.com/Textualize/rich/pull/3905
### Added

View File

@ -82,6 +82,7 @@ The following people have contributed to the development of Rich:
- [Motahhar Mokfi](https://github.com/motahhar)
- [Tomer Shalev](https://github.com/tomers)
- [Serkan UYSAL](https://github.com/uysalserkan)
- [Tomer Yogev](https://github.com/TomerYogev)
- [Zhe Huang](https://github.com/onlyacat)
- [Adrian Zuber](https://github.com/xadrianzetx)
- [Ke Sun](https://github.com/ksun212)

View File

@ -1172,9 +1172,10 @@ class Progress(JupyterMixin):
def stop(self) -> None:
"""Stop the progress display."""
self.live.stop()
if not self.console.is_interactive and not self.console.is_jupyter:
self.console.print()
if not self.disable:
self.live.stop()
if not self.console.is_interactive and not self.console.is_jupyter:
self.console.print()
def __enter__(self) -> Self:
self.start()

View File

@ -565,6 +565,30 @@ def test_no_output_if_progress_is_disabled() -> None:
assert result == expected
def test_no_output_if_progress_is_disabled_non_interactive() -> None:
console = Console(
file=io.StringIO(),
force_interactive=False,
width=60,
color_system="truecolor",
legacy_windows=False,
_environ={},
)
progress = Progress(
console=console,
disable=True,
)
test = ["foo", "bar", "baz"]
expected_values = iter(test)
with progress:
for value in progress.track(test, description="test"):
assert value == next(expected_values)
result = console.file.getvalue()
print(repr(result))
expected = ""
assert result == expected
def test_open() -> None:
console = Console(
file=io.StringIO(),