Skip to content

Add context support to progress TaskID objects #3805

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
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

AetherBreaker
Copy link

@AetherBreaker AetherBreaker commented Jul 24, 2025

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Changed progress TaskID from a simple newtype to it's own class that expects a self instance of Progress to be passed into it's constructor to allow for support of context management that automatically removes the associated task upon context exit.

with progress.add_task("Processing...", total=10) as task:
    # Do stuff
    ...
# Created progress bar is removed upon context exit

This is my first time ever making a PR and contributing to a public project before, so bear with me please.

I tried my best to follow the instructions and guidelines in the Rich contribution guide.

Tests

Almost all the tests passed except 4 which I'm not sure how to fix since I'm not experienced enough with python tests.

The tests for Tasks fail to account for the fact that TaskID now expects an instance of Progress to be passed in as a parameter, and I'm not sure how to get an instance of one within the context of each test.

test_log fails for some reason even though I never touched any code outside of progress.py. I can only assume it is something wrong with my own testing environment.

If anyone can give me advice on the best way to modify the Task tests such that they pass, it would be much appreciated.

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

Successfully merging this pull request may close these issues.

1 participant