diff options
author | Robert Graham <rpgraham84@gmail.com> | 2018-05-15 15:25:08 -0400 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2018-05-18 09:34:45 -0700 |
commit | a112bb200a54727fa5f4d72e994ca6aaf8b4a553 (patch) | |
tree | 02177eedcfc43e1a88b44eca80cb06361870048f | |
parent | d37ff750f4ba4aa5af6104f5fcaa5d81dcc227d6 (diff) | |
download | click-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.py | 11 |
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 |