Closed
Description
https://rich.readthedocs.io/en/latest/reference/progress.html#rich.progress.track reads:
Parameters:
sequence (Iterable[ProgressType]) – A sequence (must support “len”) you wish to iterate over.
In fact, the sequence
parameter is not a sequence, it is an iterable (which is correctly detected by a documentation builder, btw), so it doesn't have to support len
.
My suggestions:
add a parameter named,iterable
with the same meaning assequence
of course, keep,sequence
for backward compatibility
(edit: I do agree with current solution. Thank you.)- maybe change the type in the source code from
Sequence | Iterable
to justIterable
.
Sample program to play with (as you see, concurrent.futures.as_completed()
is not a sequence—it is a generator—so it does not have len
, and despite of that the code works correctly):
#! /usr/bin/env --split-string=uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "rich",
# ]
# ///
import concurrent.futures
import random
import time
import rich.progress
import rich.traceback
def main() -> None:
"""Top-level logic."""
rich.traceback.install(show_locals=True)
with concurrent.futures.ProcessPoolExecutor() as executor:
futures = { executor.submit(simulate_job) for i in range(15) }
for future in rich.progress.track(
concurrent.futures.as_completed(futures),
description='Working…',
# total=len(futures),
):
print('Something is done!')
def simulate_job() -> None:
"""Job simulator — sleep for a random amount of time."""
time.sleep(
random.uniform(0.1, 1.3),
)
if __name__ == '__main__':
main()
Metadata
Metadata
Assignees
Labels
No labels