summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-24 20:57:14 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-24 20:57:14 (GMT)
commitdf29c4a83d13d96cfcf809e648ee9b31a4174729 (patch)
treeb6ace06d471e23e2aabaf352fde32f8ed02241f0 /Lib
parent14199f939278d67804cf44ef0b9d32f998c62d58 (diff)
downloadcpython-df29c4a83d13d96cfcf809e648ee9b31a4174729.zip
cpython-df29c4a83d13d96cfcf809e648ee9b31a4174729.tar.gz
cpython-df29c4a83d13d96cfcf809e648ee9b31a4174729.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/tasks.py6
-rw-r--r--Lib/test/test_asyncio/test_tasks.py6
2 files changed, 8 insertions, 4 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index f5c10c8..3b41a21 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 d770a91..3037f60 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(<notmuch done at %s>)<CANCELLED>' % filename)
+ 'Task(<notmuch done at %s:%s>)<CANCELLED>'
+ % (filename, lineno))
t = asyncio.Task(notmuch(), loop=self.loop)
self.loop.run_until_complete(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):
@asyncio.coroutine