Fix: Flush remaining accumulated steps in ProgressBar.finish() so show_pos displays full completion

Fixed pallets/click#3571 — 1 line bug-fix.

The Bug

Repo: pallets/click Issue: #3571 Status: patch-ready

Description: Flush remaining accumulated steps in ProgressBar.finish() so show_pos displays full completion

Fix scope: 1 line changed in src/click/_termui_impl.py

Root Cause

The edge case in class ProgressBar(t.Generic[V]): at src/click/_termui_impl.py causes incorrect behavior when a specific input condition is met. In Python, this pattern is easy to miss because standard test suites rarely cover every boundary condition.

The fix is a surgical change — it addresses exactly the failing condition without refactoring surrounding code. This minimizes the risk of introducing new bugs.

Impact: The bug affects users who hit the specific edge case. For click, this means 1 line fixes a scenario that could cause incorrect output, crashes, or silent data corruption depending on the code path.

The Fix

This is a surgical fix — every line is deliberate and scoped to exactly the problem.

@@ -348,6 +348,7 @@ class ProgressBar(t.Generic[V]):
             self._completed_intervals = 0
 
     def finish(self) -> None:
+        self.make_step(self._completed_intervals)
         self.eta_known = False
         self.current_item = None
         self.finished = True

Pattern & Takeaways

Pattern: Edge case in class ProgressBar(t.Generic[V]): — the Python code path was not tested with the specific input that triggers the failure. The surgical fix demonstrates that the most reliable approach is to change the minimum necessary code.

Key insight: The most predictable bugs are edge cases at input boundaries. Every function that accepts parameters has boundary conditions that example-based tests may miss. Code review should focus on: (1) What happens with empty/null input? (2) What happens at iteration boundaries? (3) What happens with unexpected types?

Transfer Potential

Varies — edge case fixes are repo-specific in detail but universal in pattern. The minimal-change principle and boundary-condition thinking transfer to any codebase. Reading this post helps recognize similar patterns in your own projects.


Auto-generated from PR #3571. View all patches on GitHub.