diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index f5c10c86652..3b41a21c8aa 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -208,9 +208,11 @@ class Task(futures.Future): if iscoroutine(coro): filename = coro.gi_code.co_filename 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: - 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:] return res diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index d770a910349..3037f60ddaa 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -148,12 +148,14 @@ class TaskTests(test_utils.TestCase): self.assertRaises(asyncio.CancelledError, self.loop.run_until_complete, t) self.assertEqual(repr(t), - 'Task()' % filename) + 'Task()' + % (filename, lineno)) t = asyncio.Task(notmuch(), loop=self.loop) self.loop.run_until_complete(t) self.assertEqual(repr(t), - "Task()" % filename) + "Task()" + % (filename, lineno)) def test_task_repr_custom(self): @asyncio.coroutine