From a112bb200a54727fa5f4d72e994ca6aaf8b4a553 Mon Sep 17 00:00:00 2001 From: Robert Graham Date: Tue, 15 May 2018 15:25:08 -0400 Subject: [PATCH] Fixes issue #447 Fixes a ZeroDivisionError in ProgressBar.make_step when the first arg passed to the first call of ProgressBar.update is 0. --- click/_termui_impl.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/click/_termui_impl.py b/click/_termui_impl.py index 0c815a25d..0b39731cd 100644 --- a/click/_termui_impl.py +++ b/click/_termui_impl.py @@ -245,7 +245,16 @@ def make_step(self, n_steps): return self.last_eta = time.time() - self.avg = self.avg[-6:] + [-(self.start - time.time()) / (self.pos)] + + # self.avg is a rolling list of length <= 7 of steps where steps are + # defined as time elapsed divided by the total progress through + # self.length. + if self.pos: + step = (time.time() - self.start) / self.pos + else: + step = time.time() - self.start + + self.avg = self.avg[-6:] + [step] self.eta_known = self.length_known