Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
andrei-korshikov opened this issue Apr 20, 2025 · 1 comment

Comments

@andrei-korshikov
Copy link

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,
  • 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()
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant