Skip to content

Commit 09197b3

Browse files
committed
asyncio: sync with Tulip
- CoroWrapper.__del__() now reuses repr(CoroWrapper) to log the "... was never yielded from" warning - Improve CoroWrapper: copy also the qualified name on Python 3.4, not only on Python 3.5+
1 parent 1964a8a commit 09197b3

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

Lib/asyncio/coroutines.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
_DEBUG = (not sys.flags.ignore_environment
3030
and bool(os.environ.get('PYTHONASYNCIODEBUG')))
3131

32-
_PY35 = (sys.version_info >= (3, 5))
33-
3432

3533
# Check for CPython issue #21209
3634
def has_yield_from_bug():
@@ -119,8 +117,7 @@ def __del__(self):
119117
gen = getattr(self, 'gen', None)
120118
frame = getattr(gen, 'gi_frame', None)
121119
if frame is not None and frame.f_lasti == -1:
122-
func = events._format_callback(self.func, ())
123-
msg = 'Coroutine %s was never yielded from' % func
120+
msg = '%r was never yielded from' % self
124121
tb = getattr(self, '_source_traceback', ())
125122
if tb:
126123
tb = ''.join(traceback.format_list(tb))
@@ -155,7 +152,7 @@ def wrapper(*args, **kwds):
155152
if w._source_traceback:
156153
del w._source_traceback[-1]
157154
w.__name__ = func.__name__
158-
if _PY35:
155+
if hasattr(func, '__qualname__'):
159156
w.__qualname__ = func.__qualname__
160157
w.__doc__ = func.__doc__
161158
return w
@@ -178,10 +175,7 @@ def iscoroutine(obj):
178175

179176
def _format_coroutine(coro):
180177
assert iscoroutine(coro)
181-
if _PY35:
182-
coro_name = coro.__qualname__
183-
else:
184-
coro_name = coro.__name__
178+
coro_name = getattr(coro, '__qualname__', coro.__name__)
185179

186180
filename = coro.gi_code.co_filename
187181
if (isinstance(coro, CoroWrapper)

Lib/asyncio/tasks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from .log import logger
2222

2323
_PY34 = (sys.version_info >= (3, 4))
24-
_PY35 = (sys.version_info >= (3, 5))
2524

2625

2726
class Task(futures.Future):

Lib/test/test_asyncio/test_tasks.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def notmuch():
150150

151151
# test coroutine object
152152
gen = notmuch()
153-
if PY35:
153+
if coroutines._DEBUG or PY35:
154154
coro_qualname = 'TaskTests.test_task_repr.<locals>.notmuch'
155155
else:
156156
coro_qualname = 'notmuch'
@@ -205,17 +205,12 @@ def notmuch():
205205

206206
# test coroutine object
207207
gen = notmuch()
208-
if PY35:
208+
if coroutines._DEBUG or PY35:
209209
# On Python >= 3.5, generators now inherit the name of the
210210
# function, as expected, and have a qualified name (__qualname__
211211
# attribute).
212212
coro_name = 'notmuch'
213213
coro_qualname = 'TaskTests.test_task_repr_coro_decorator.<locals>.notmuch'
214-
elif coroutines._DEBUG:
215-
# In debug mode, @coroutine decorator uses CoroWrapper which gets
216-
# its name (__name__ attribute) from the wrapped coroutine
217-
# function.
218-
coro_name = coro_qualname = 'notmuch'
219214
else:
220215
# On Python < 3.5, generators inherit the name of the code, not of
221216
# the function. See: http://bugs.python.org/issue21205
@@ -1653,7 +1648,7 @@ def coro_noop():
16531648
self.assertTrue(m_log.error.called)
16541649
message = m_log.error.call_args[0][0]
16551650
func_filename, func_lineno = test_utils.get_function_source(coro_noop)
1656-
regex = (r'^Coroutine %s\(\) at %s:%s was never yielded from\n'
1651+
regex = (r'^<CoroWrapper %s\(\) .* at %s:%s, .*> was never yielded from\n'
16571652
r'Coroutine object created at \(most recent call last\):\n'
16581653
r'.*\n'
16591654
r' File "%s", line %s, in test_coroutine_never_yielded\n'

0 commit comments

Comments
 (0)