rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

Calling `bar(int)` in definite mode causes a crash #85

Closed awbacker closed 3 years ago

awbacker commented 3 years ago

The following code will crash on the latest version of alive_bar:

with alive_bar(total=100) as bar:
    time.sleep(0.2)
    bar(10)

Traceback (most recent call last):
  File "main.py", line 30, in <module>
    bar(10)
  File "{venv}/lib/python3.9/site-packages/alive_progress/core/progress.py", line 157, in bar_handle
    set_text(text)
  File "{venv}/lib/python3.9/site-packages/alive_progress/core/progress.py", line 126, in set_text
    run.text = sanitize_text_marking_wide_chars(message)
  File "{venv}/lib/python3.9/site-packages/alive_progress/core/utils.py", line 35, in sanitize_text_marking_wide_chars
    text = ' '.join((text or '').split())
AttributeError: 'int' object has no attribute 'split'

The documentation states this is the way to update the bar in definite mode

in definite and unknown modes, it accepts an optional int argument, which increments the counter by any positive number, like bar(5) to increment the counter by 5 in one step āž” relative positioning;

After inspecting the bar_handle function (thanks mr. stack-trace!), it appears that the incr parameter is the way to update the step.

with alive_bar(total=100) as bar:
    bar(incr=10)
TheTechRobo commented 3 years ago

"latest version" I assume version 1.6.2? Could you test it on #51 (2.0)?

rsalmei commented 3 years ago

Hey man! I'm glad you already found out what did happen...

It's exactly what you said, in the published version you'll need incr. I chose at the time to document the new signature, so that people would read and internalize the more correct and permanent way. I also marked the code with a DeprecationWarning on the text param, which came earlier. So, in the next version, I can remove it and fulfill the signature I documented...

But I'm sorry about that, maybe that was a poor decision. Fortunately like @TheTechRobo has said, the 2.0 is finally just around the corner!

rsalmei commented 3 years ago

Closing this one as it is not actually a problem, just the documentation that is more up to date, before the code ships šŸ‘