mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
(Merge 3.4) 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+
This commit is contained in:
commit
e77b5a775a
3 changed files with 6 additions and 18 deletions
|
@ -29,8 +29,6 @@ _YIELD_FROM = opcode.opmap['YIELD_FROM']
|
||||||
_DEBUG = (not sys.flags.ignore_environment
|
_DEBUG = (not sys.flags.ignore_environment
|
||||||
and bool(os.environ.get('PYTHONASYNCIODEBUG')))
|
and bool(os.environ.get('PYTHONASYNCIODEBUG')))
|
||||||
|
|
||||||
_PY35 = (sys.version_info >= (3, 5))
|
|
||||||
|
|
||||||
|
|
||||||
# Check for CPython issue #21209
|
# Check for CPython issue #21209
|
||||||
def has_yield_from_bug():
|
def has_yield_from_bug():
|
||||||
|
@ -119,8 +117,7 @@ class CoroWrapper:
|
||||||
gen = getattr(self, 'gen', None)
|
gen = getattr(self, 'gen', None)
|
||||||
frame = getattr(gen, 'gi_frame', None)
|
frame = getattr(gen, 'gi_frame', None)
|
||||||
if frame is not None and frame.f_lasti == -1:
|
if frame is not None and frame.f_lasti == -1:
|
||||||
func = events._format_callback(self.func, ())
|
msg = '%r was never yielded from' % self
|
||||||
msg = 'Coroutine %s was never yielded from' % func
|
|
||||||
tb = getattr(self, '_source_traceback', ())
|
tb = getattr(self, '_source_traceback', ())
|
||||||
if tb:
|
if tb:
|
||||||
tb = ''.join(traceback.format_list(tb))
|
tb = ''.join(traceback.format_list(tb))
|
||||||
|
@ -155,7 +152,7 @@ def coroutine(func):
|
||||||
if w._source_traceback:
|
if w._source_traceback:
|
||||||
del w._source_traceback[-1]
|
del w._source_traceback[-1]
|
||||||
w.__name__ = func.__name__
|
w.__name__ = func.__name__
|
||||||
if _PY35:
|
if hasattr(func, '__qualname__'):
|
||||||
w.__qualname__ = func.__qualname__
|
w.__qualname__ = func.__qualname__
|
||||||
w.__doc__ = func.__doc__
|
w.__doc__ = func.__doc__
|
||||||
return w
|
return w
|
||||||
|
@ -178,10 +175,7 @@ def iscoroutine(obj):
|
||||||
|
|
||||||
def _format_coroutine(coro):
|
def _format_coroutine(coro):
|
||||||
assert iscoroutine(coro)
|
assert iscoroutine(coro)
|
||||||
if _PY35:
|
coro_name = getattr(coro, '__qualname__', coro.__name__)
|
||||||
coro_name = coro.__qualname__
|
|
||||||
else:
|
|
||||||
coro_name = coro.__name__
|
|
||||||
|
|
||||||
filename = coro.gi_code.co_filename
|
filename = coro.gi_code.co_filename
|
||||||
if (isinstance(coro, CoroWrapper)
|
if (isinstance(coro, CoroWrapper)
|
||||||
|
|
|
@ -21,7 +21,6 @@ from .coroutines import coroutine
|
||||||
from .log import logger
|
from .log import logger
|
||||||
|
|
||||||
_PY34 = (sys.version_info >= (3, 4))
|
_PY34 = (sys.version_info >= (3, 4))
|
||||||
_PY35 = (sys.version_info >= (3, 5))
|
|
||||||
|
|
||||||
|
|
||||||
class Task(futures.Future):
|
class Task(futures.Future):
|
||||||
|
|
|
@ -150,7 +150,7 @@ class TaskTests(test_utils.TestCase):
|
||||||
|
|
||||||
# test coroutine object
|
# test coroutine object
|
||||||
gen = notmuch()
|
gen = notmuch()
|
||||||
if PY35:
|
if coroutines._DEBUG or PY35:
|
||||||
coro_qualname = 'TaskTests.test_task_repr.<locals>.notmuch'
|
coro_qualname = 'TaskTests.test_task_repr.<locals>.notmuch'
|
||||||
else:
|
else:
|
||||||
coro_qualname = 'notmuch'
|
coro_qualname = 'notmuch'
|
||||||
|
@ -205,17 +205,12 @@ class TaskTests(test_utils.TestCase):
|
||||||
|
|
||||||
# test coroutine object
|
# test coroutine object
|
||||||
gen = notmuch()
|
gen = notmuch()
|
||||||
if PY35:
|
if coroutines._DEBUG or PY35:
|
||||||
# On Python >= 3.5, generators now inherit the name of the
|
# On Python >= 3.5, generators now inherit the name of the
|
||||||
# function, as expected, and have a qualified name (__qualname__
|
# function, as expected, and have a qualified name (__qualname__
|
||||||
# attribute).
|
# attribute).
|
||||||
coro_name = 'notmuch'
|
coro_name = 'notmuch'
|
||||||
coro_qualname = 'TaskTests.test_task_repr_coro_decorator.<locals>.notmuch'
|
coro_qualname = 'TaskTests.test_task_repr_coro_decorator.<locals>.notmuch'
|
||||||
elif coroutines._DEBUG:
|
|
||||||
# In debug mode, @coroutine decorator uses CoroWrapper which gets
|
|
||||||
# its name (__name__ attribute) from the wrapped coroutine
|
|
||||||
# function.
|
|
||||||
coro_name = coro_qualname = 'notmuch'
|
|
||||||
else:
|
else:
|
||||||
# On Python < 3.5, generators inherit the name of the code, not of
|
# On Python < 3.5, generators inherit the name of the code, not of
|
||||||
# the function. See: http://bugs.python.org/issue21205
|
# the function. See: http://bugs.python.org/issue21205
|
||||||
|
@ -1653,7 +1648,7 @@ class TaskTests(test_utils.TestCase):
|
||||||
self.assertTrue(m_log.error.called)
|
self.assertTrue(m_log.error.called)
|
||||||
message = m_log.error.call_args[0][0]
|
message = m_log.error.call_args[0][0]
|
||||||
func_filename, func_lineno = test_utils.get_function_source(coro_noop)
|
func_filename, func_lineno = test_utils.get_function_source(coro_noop)
|
||||||
regex = (r'^Coroutine %s\(\) at %s:%s was never yielded from\n'
|
regex = (r'^<CoroWrapper %s\(\) .* at %s:%s, .*> was never yielded from\n'
|
||||||
r'Coroutine object created at \(most recent call last\):\n'
|
r'Coroutine object created at \(most recent call last\):\n'
|
||||||
r'.*\n'
|
r'.*\n'
|
||||||
r' File "%s", line %s, in test_coroutine_never_yielded\n'
|
r' File "%s", line %s, in test_coroutine_never_yielded\n'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue