wolph / python-progressbar

Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"
http://progressbar-2.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
860 stars 102 forks source link

ProgressBar update no longer works with floats. #292

Closed dsemi closed 9 months ago

dsemi commented 9 months ago

Description

Not sure if this was intentional or an oversight, but there doesn't appear to be any reason that floating point values can't be used when updating the current state of the progress bar.

78c95b649984b1610d1d4420143baeaa31252d00 added an isinstance(value, int) check at the beginning of ProgressBar.update, that should probably either throw a type error if floating points are not intended to be supported anymore, or updated to be (isinstance(value, int) or isinstance(value, float)).

Code

import time
import progressbar

widgets = ['Test ', progressbar.Bar(), ' ', progressbar.Percentage('%(percentage)6.2f%%'), ' ', progressbar.AdaptiveETA()]
with progressbar.ProgressBar(widgets=widgets, max_value=20) as bar:
  for i in range(20):
    bar.update(i+0.1)
    time.sleep(0.5)

When running this, the bar does not update until the loop finishes. Removing the + 0.1 causes the bar to update as expected.

wolph commented 9 months ago

That was indeed not the intended effect, I've readded float compatibility. Thanks for the heads up!

wolph commented 9 months ago

I've created a new release with a fix :)

dsemi commented 9 months ago

Thanks for the quick response!