Adjusted TaskID to not need the use of functools.partial

This commit is contained in:
Jacob Ogden 2025-07-24 12:00:20 -04:00
parent ab786c840c
commit 7cf2fb8fea
3 changed files with 4 additions and 3 deletions

View file

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added `TTY_INTERACTIVE` environment variable to force interactive mode off or on https://github.com/Textualize/rich/pull/3777
- Added Context Manager support for TaskID objects returned by Progress.add_task. Allowing for `with progress.add_task(...) as taskid: ...` which automatically removes the progress bar for that task upon exiting the current context.
## [14.0.0] - 2025-03-30

View file

@ -94,3 +94,4 @@ The following people have contributed to the development of Rich:
- [Jonathan Helmus](https://github.com/jjhelmus)
- [Brandon Capener](https://github.com/bcapener)
- [Alex Zheng](https://github.com/alexzheng111)
- [Jacob Ogden](https://github.com/AetherBreaker)

View file

@ -7,7 +7,6 @@ from abc import ABC, abstractmethod
from collections import deque
from dataclasses import dataclass, field
from datetime import timedelta
from functools import partial
from io import RawIOBase, UnsupportedOperation
from math import ceil
from mmap import mmap
@ -64,7 +63,7 @@ class TaskID(int):
return super().__new__(cls, task_id)
def __init__(self, task_id: int, prog_instance: Progress | type[Progress]):
self.remove = partial(prog_instance.remove_task, self)
self.prog = prog_instance
def __enter__(self) -> Self:
return self
@ -75,7 +74,7 @@ class TaskID(int):
exc_value: BaseException | None,
traceback: TracebackType | None,
):
self.remove()
self.prog.remove_task(self)
class _TrackThread(Thread):