bpo-46752: Uniform TaskGroup.__repr__ (GH-31409)

This commit is contained in:
Andrew Svetlov 2022-02-20 12:07:00 +02:00 committed by GitHub
parent 12a2e41e8a
commit e7130c2e8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: