Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4802c6e

Browse files
committed
Sync asyncio with Tulip: Fix test_tasks for Python 3.5
On Python 3.5, generator now gets their name from the function, no more from the code. So we get the expected "notmuch" name instead of the generic "coro" name.
1 parent 5b1fdc1 commit 4802c6e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Lib/test/test_asyncio/test_tasks.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import gc
44
import os.path
5+
import sys
56
import types
67
import unittest
78
import weakref
@@ -154,10 +155,13 @@ def __repr__(self):
154155
t = MyTask(gen, loop=self.loop)
155156
filename = gen.gi_code.co_filename
156157
lineno = gen.gi_frame.f_lineno
157-
# FIXME: check for the name "coro" instead of "notmuch" because
158-
# @asyncio.coroutine drops the name of the wrapped function:
159-
# http://bugs.python.org/issue21205
160-
self.assertEqual(repr(t), 'T[](<coro at %s:%s>)' % (filename, lineno))
158+
if sys.version_info >= (3, 5):
159+
name = 'notmuch'
160+
else:
161+
# On Python < 3.5, generators inherit the name of the code, not of
162+
# the function. See: http://bugs.python.org/issue21205
163+
name = 'coro'
164+
self.assertEqual(repr(t), 'T[](<%s at %s:%s>)' % (name, filename, lineno))
161165

162166
def test_task_basics(self):
163167
@asyncio.coroutine

0 commit comments

Comments
 (0)