[Python-checkins] bpo-46752: Uniform TaskGroup.__repr__ (GH-31409)
asvetlov
webhook-mailer at python.org
Sun Feb 20 05:07:16 EST 2022
https://github.com/python/cpython/commit/e7130c2e8c6abfaf04b209bd5b239059eda024b9
commit: e7130c2e8c6abfaf04b209bd5b239059eda024b9
branch: main
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2022-02-20T12:07:00+02:00
summary:
bpo-46752: Uniform TaskGroup.__repr__ (GH-31409)
files:
M Lib/asyncio/taskgroups.py
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 57b0eafefc16f..756fc551e013d 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -9,6 +9,7 @@
from . import exceptions
from . import tasks
+
class TaskGroup:
def __init__(self):
@@ -25,19 +26,20 @@ def __init__(self):
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:
More information about the Python-checkins
mailing list