Outdated documentation for Spinner
See original GitHub issueDescription
The current docstring in the Spinner class demonstrates using s.next()
to update the spinner. But this is a Python 2-ism that no longer exists for iterators in Python 3. Instead the correct documentation would be next(s)
.
Additionally, I think it’s confusing that the API for Spinner
is so different from ProgressBar
and ProgressBarOrSpinner
. In the latter two cases, their __enter__
method (when using with ProgressBar(...) as bar:
returns the ProgressBar(OrSpinner)
instance itself, which is iterable itself. It also provides an update()
method which can be called to update the progress bar. Whereas with Spinner(...) as s:
does not return the Spinner
instance itself, but rather a generator.
It should be easy to update the API for Spinner
(make it iterable, make __enter__
return the Spinner
instance, and add an update()
method) so that it is more like ProgressBar
.
I would suggest making the updates to Spinner
and fixing the documentation at the same time.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
I swear this issue is cursed.
That’s a good point and exposes another inconsistency between
Spinner
andProgressBar
, where the latter can take a length/iterator as an argument. This makes sense since a progress bar is more for something with a known amount of work, while a spinner is for an unknown amount of work. Though sometimes iterators are non-finite, and it would be useful to wrap such an iterator in a spinner.That said, your for loop example is still useful (though it would also be used with a
with
statement to properly cancel the spinner when done, like:This is equivalent to having a
while True:
loop that you eventually have tobreak
out of, except it updates the spinner while looping.Meanwhile having an
update()
method would just be equivalent to callingnext(spinner)
.Basically this would be matter of:
Spinner.__init__
so it doesself._iter = self._iterator()
(orself._silent_iterator
)__enter__
to justreturn self
and also add__iter__
which does the same (return self
)__next__
which takesnext(self._iter)
update()
which callsnext(self)