Skip to content

Fix #1658: apply disp_trim to all format_meter return paths - #1717

Merged
casperdcl merged 1 commit into
tqdm:masterfrom
cobyfrombrooklyn-bot:fix-issue-1658
Jul 7, 2026
Merged

casperdcl merged 1 commit into
tqdm:masterfrom
cobyfrombrooklyn-bot:fix-issue-1658

Conversation

@cobyfrombrooklyn-bot

Copy link
Copy Markdown

format_meter has 6 return statements but only 2 applied disp_trim when ncols is set. This meant custom bar_format without {bar} and the no-total stats-only path would produce output wider than the terminal.

Fix

Applied disp_trim(result, ncols) if ncols else result to the 3 return paths that were missing it:

  1. bar_format without {bar}, with total (line 633)
  2. bar_format without {bar}, without total (line 652)
  3. No bar_format, no total - stats only (line 660)

The ncols==0 early return (line 618) is left as-is since it intentionally produces a compact format.

Test

Added test_disp_trim_all_format_meter_paths that verifies all three paths respect ncols=20 trimming. Without the fix, the first assertion fails (disp_len is 38, exceeding ncols of 20).

Full test suite passes (71 tests) on macOS ARM (Apple Silicon).

Fixes #1658

format_meter has 6 return statements but only 2 applied disp_trim
when ncols is set. This meant custom bar_format without {bar} and
the no-total stats-only path would not respect ncols, producing
output wider than the terminal.

Now all return paths (except ncols==0 which is intentionally compact)
apply disp_trim consistently.

Fixes tqdm#1658
@casperdcl
casperdcl force-pushed the master branch 3 times, most recently from a09a105 to 4b33952 Compare June 9, 2026 13:22
@casperdcl
casperdcl merged commit 3757d0d into tqdm:master Jul 7, 2026
1 check passed
@casperdcl

Copy link
Copy Markdown
Member

Thanks for this! Apologies for the delay. Merged with #1767.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-bug-warning ⚠ Visual output bad

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

disp_trim is not called for all return values of format_meter

2 participants