mirror of
https://github.com/Textualize/rich.git
synced 2025-08-22 19:24:24 +00:00
Adjusted TaskID to not need the use of functools.partial
This commit is contained in:
parent
ab786c840c
commit
7cf2fb8fea
3 changed files with 4 additions and 3 deletions
|
@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added `TTY_INTERACTIVE` environment variable to force interactive mode off or on https://github.com/Textualize/rich/pull/3777
|
- 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
|
## [14.0.0] - 2025-03-30
|
||||||
|
|
||||||
|
|
|
@ -94,3 +94,4 @@ The following people have contributed to the development of Rich:
|
||||||
- [Jonathan Helmus](https://github.com/jjhelmus)
|
- [Jonathan Helmus](https://github.com/jjhelmus)
|
||||||
- [Brandon Capener](https://github.com/bcapener)
|
- [Brandon Capener](https://github.com/bcapener)
|
||||||
- [Alex Zheng](https://github.com/alexzheng111)
|
- [Alex Zheng](https://github.com/alexzheng111)
|
||||||
|
- [Jacob Ogden](https://github.com/AetherBreaker)
|
||||||
|
|
|
@ -7,7 +7,6 @@ from abc import ABC, abstractmethod
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import partial
|
|
||||||
from io import RawIOBase, UnsupportedOperation
|
from io import RawIOBase, UnsupportedOperation
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from mmap import mmap
|
from mmap import mmap
|
||||||
|
@ -64,7 +63,7 @@ class TaskID(int):
|
||||||
return super().__new__(cls, task_id)
|
return super().__new__(cls, task_id)
|
||||||
|
|
||||||
def __init__(self, task_id: int, prog_instance: Progress | type[Progress]):
|
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:
|
def __enter__(self) -> Self:
|
||||||
return self
|
return self
|
||||||
|
@ -75,7 +74,7 @@ class TaskID(int):
|
||||||
exc_value: BaseException | None,
|
exc_value: BaseException | None,
|
||||||
traceback: TracebackType | None,
|
traceback: TracebackType | None,
|
||||||
):
|
):
|
||||||
self.remove()
|
self.prog.remove_task(self)
|
||||||
|
|
||||||
|
|
||||||
class _TrackThread(Thread):
|
class _TrackThread(Thread):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue