Skip to content
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

[REQUEST] Progress.tasks should return a Dict instead of a List #3340

Open
digital-idiot opened this issue Apr 19, 2024 · 1 comment
Open

Comments

@digital-idiot
Copy link

Currently Progress.tasks method (property) returns a list of tasks. This makes querying a task with their task_id a bit cumbersome. Consider the scenario when some tasks are removed which causes mismatch between task_id and list indexes. Since the task_id of each task is unique why not return a dict in the format {task_id: <task_object>, ...} instead. That would be much more convenient and intuitive. Consider the following snippet:

from time import sleep
from rich.progress import Progress


with Progress() as phost:
    t1 = phost.add_task(description="Foo:", total=30)
    t2 = phost.add_task(description="Bar:", total=50)
    for i in range(30):
        phost.update(t1, advance=1)
        sleep(0.1)
    if phost.tasks[t1].finished:
        phost.remove_task(t1)
    for j in range(50):
        phost.update(t2, advance=1)
        sleep(0.1)
    if phost.tasks[t2].finished:  # Index error here!!
        phost.remove_task(t2)
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
Projects
None yet
Development

No branches or pull requests

1 participant