summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Graham <rpgraham84@gmail.com>2018-05-15 15:25:08 -0400
committerDavid Lord <davidism@gmail.com>2018-05-18 09:34:45 -0700
commita112bb200a54727fa5f4d72e994ca6aaf8b4a553 (patch)
tree02177eedcfc43e1a88b44eca80cb06361870048f
parentd37ff750f4ba4aa5af6104f5fcaa5d81dcc227d6 (diff)
downloadclick-a112bb200a54727fa5f4d72e994ca6aaf8b4a553.tar.gz
Fixes issue #447
Fixes a ZeroDivisionError in ProgressBar.make_step when the first arg passed to the first call of ProgressBar.update is 0.
-rw-r--r--click/_termui_impl.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/click/_termui_impl.py b/click/_termui_impl.py
index 0c815a2..0b39731 100644
--- a/click/_termui_impl.py
+++ b/click/_termui_impl.py
@@ -245,7 +245,16 @@ class ProgressBar(object):
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