Kaydet (Commit) 5c2f5ab4 authored tarafından Victor Stinner's avatar Victor Stinner

(Merge 3.4) asyncio: repr(Task) now also contains the line number even if the

coroutine is done: use the first line number of the code object instead of the
current line number of the generator frame.

The name of the coroutine is not enough because many coroutines may have the
same name. It's a common case in asyncio tests for example.
...@@ -208,9 +208,11 @@ class Task(futures.Future): ...@@ -208,9 +208,11 @@ class Task(futures.Future):
if iscoroutine(coro): if iscoroutine(coro):
filename = coro.gi_code.co_filename filename = coro.gi_code.co_filename
if coro.gi_frame is not None: if coro.gi_frame is not None:
text += ' at %s:%s' % (filename, coro.gi_frame.f_lineno) lineno = coro.gi_frame.f_lineno
text += ' at %s:%s' % (filename, lineno)
else: else:
text += ' done at %s' % filename lineno = coro.gi_code.co_firstlineno
text += ' done at %s:%s' % (filename, lineno)
res = res[:i] + '(<{}>)'.format(text) + res[i:] res = res[:i] + '(<{}>)'.format(text) + res[i:]
return res return res
......
...@@ -148,12 +148,14 @@ class TaskTests(test_utils.TestCase): ...@@ -148,12 +148,14 @@ class TaskTests(test_utils.TestCase):
self.assertRaises(asyncio.CancelledError, self.assertRaises(asyncio.CancelledError,
self.loop.run_until_complete, t) self.loop.run_until_complete, t)
self.assertEqual(repr(t), self.assertEqual(repr(t),
'Task(<notmuch done at %s>)<CANCELLED>' % filename) 'Task(<notmuch done at %s:%s>)<CANCELLED>'
% (filename, lineno))
t = asyncio.Task(notmuch(), loop=self.loop) t = asyncio.Task(notmuch(), loop=self.loop)
self.loop.run_until_complete(t) self.loop.run_until_complete(t)
self.assertEqual(repr(t), self.assertEqual(repr(t),
"Task(<notmuch done at %s>)<result='abc'>" % filename) "Task(<notmuch done at %s:%s>)<result='abc'>"
% (filename, lineno))
def test_task_repr_custom(self): def test_task_repr_custom(self):
@asyncio.coroutine @asyncio.coroutine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment