diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2022-02-20 10:07:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-20 10:07:00 (GMT) |
commit | e7130c2e8c6abfaf04b209bd5b239059eda024b9 (patch) | |
tree | fef3ec70a469d04808f352397e1fb4ff0fd92b79 /Lib | |
parent | 12a2e41e8a276ec3a68f3e5f94b02752185c66fb (diff) | |
download | cpython-e7130c2e8c6abfaf04b209bd5b239059eda024b9.zip cpython-e7130c2e8c6abfaf04b209bd5b239059eda024b9.tar.gz cpython-e7130c2e8c6abfaf04b209bd5b239059eda024b9.tar.bz2 |
bpo-46752: Uniform TaskGroup.__repr__ (GH-31409)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/taskgroups.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py index 57b0eaf..756fc55 100644 --- a/Lib/asyncio/taskgroups.py +++ b/Lib/asyncio/taskgroups.py @@ -9,6 +9,7 @@ from . import events from . import exceptions from . import tasks + class TaskGroup: def __init__(self): @@ -25,19 +26,20 @@ class TaskGroup: self._on_completed_fut = None def __repr__(self): - msg = f'<TaskGroup' + info = [''] if self._tasks: - msg += f' tasks:{len(self._tasks)}' + info.append(f'tasks={len(self._tasks)}') if self._unfinished_tasks: - msg += f' unfinished:{self._unfinished_tasks}' + info.append(f'unfinished={self._unfinished_tasks}') if self._errors: - msg += f' errors:{len(self._errors)}' + info.append(f'errors={len(self._errors)}') if self._aborting: - msg += ' cancelling' + info.append('cancelling') elif self._entered: - msg += ' entered' - msg += '>' - return msg + info.append('entered') + + info_str = ' '.join(info) + return f'<TaskGroup{info_str}>' async def __aenter__(self): if self._entered: |