Skip to content

[DOC BUG] rich.progress.track() documentation uses "sequence" instead of "iterable" #3706

Closed
@andrei-korshikov

Description

@andrei-korshikov

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 as sequence,
  • 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 just Iterable.

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions