[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) asyncio: repr(Task) now also contains the line number even if the

victor.stinner python-checkins at python.org
Tue Jun 24 22:58:38 CEST 2014


http://hg.python.org/cpython/rev/4a0a0d4d5fd5
changeset:   91366:4a0a0d4d5fd5
parent:      91363:e67ad57eed26
parent:      91365:3bedc1846202
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Jun 24 22:58:23 2014 +0200
summary:
  (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.

files:
  Lib/asyncio/tasks.py                |  6 ++++--
  Lib/test/test_asyncio/test_tasks.py |  6 ++++--
  2 files changed, 8 insertions(+), 4 deletions(-)


diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -208,9 +208,11 @@
         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
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -148,12 +148,14 @@
         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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list