summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2015-05-03 01:38:24 (GMT)
committerGuido van Rossum <guido@python.org>2015-05-03 01:38:24 (GMT)
commit0a9933ebf3704540a5f31225b26acb990e1de4bf (patch)
treeaabc7b609ae15cc12bf49cd4451122d2c661c471 /Lib/asyncio
parent4590c3d944230aff3d1e6810d3113e790922359c (diff)
downloadcpython-0a9933ebf3704540a5f31225b26acb990e1de4bf.zip
cpython-0a9933ebf3704540a5f31225b26acb990e1de4bf.tar.gz
cpython-0a9933ebf3704540a5f31225b26acb990e1de4bf.tar.bz2
Asyncio issue 222 / PR 231 (Victor Stinner) -- fix @coroutine functions without __name__.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/coroutines.py18
-rw-r--r--Lib/asyncio/events.py14
-rw-r--r--Lib/asyncio/futures.py2
3 files changed, 23 insertions, 11 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index a1b2875..c639461 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -151,7 +151,8 @@ def coroutine(func):
w = CoroWrapper(coro(*args, **kwds), func)
if w._source_traceback:
del w._source_traceback[-1]
- w.__name__ = func.__name__
+ if hasattr(func, '__name__'):
+ w.__name__ = func.__name__
if hasattr(func, '__qualname__'):
w.__qualname__ = func.__qualname__
w.__doc__ = func.__doc__
@@ -175,25 +176,30 @@ def iscoroutine(obj):
def _format_coroutine(coro):
assert iscoroutine(coro)
- coro_name = getattr(coro, '__qualname__', coro.__name__)
+
+ if isinstance(coro, CoroWrapper):
+ func = coro.func
+ else:
+ func = coro
+ coro_name = events._format_callback(func, ())
filename = coro.gi_code.co_filename
if (isinstance(coro, CoroWrapper)
and not inspect.isgeneratorfunction(coro.func)):
filename, lineno = events._get_function_source(coro.func)
if coro.gi_frame is None:
- coro_repr = ('%s() done, defined at %s:%s'
+ coro_repr = ('%s done, defined at %s:%s'
% (coro_name, filename, lineno))
else:
- coro_repr = ('%s() running, defined at %s:%s'
+ coro_repr = ('%s running, defined at %s:%s'
% (coro_name, filename, lineno))
elif coro.gi_frame is not None:
lineno = coro.gi_frame.f_lineno
- coro_repr = ('%s() running at %s:%s'
+ coro_repr = ('%s running at %s:%s'
% (coro_name, filename, lineno))
else:
lineno = coro.gi_code.co_firstlineno
- coro_repr = ('%s() done, defined at %s:%s'
+ coro_repr = ('%s done, defined at %s:%s'
% (coro_name, filename, lineno))
return coro_repr
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 8a7bb81..3b907c6 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -54,15 +54,21 @@ def _format_callback(func, args, suffix=''):
suffix = _format_args(args) + suffix
return _format_callback(func.func, func.args, suffix)
- func_repr = getattr(func, '__qualname__', None)
- if not func_repr:
+ if hasattr(func, '__qualname__'):
+ func_repr = getattr(func, '__qualname__')
+ elif hasattr(func, '__name__'):
+ func_repr = getattr(func, '__name__')
+ else:
func_repr = repr(func)
if args is not None:
func_repr += _format_args(args)
if suffix:
func_repr += suffix
+ return func_repr
+def _format_callback_source(func, args):
+ func_repr = _format_callback(func, args)
source = _get_function_source(func)
if source:
func_repr += ' at %s:%s' % source
@@ -92,7 +98,7 @@ class Handle:
if self._cancelled:
info.append('cancelled')
if self._callback is not None:
- info.append(_format_callback(self._callback, self._args))
+ info.append(_format_callback_source(self._callback, self._args))
if self._source_traceback:
frame = self._source_traceback[-1]
info.append('created at %s:%s' % (frame[0], frame[1]))
@@ -119,7 +125,7 @@ class Handle:
try:
self._callback(*self._args)
except Exception as exc:
- cb = _format_callback(self._callback, self._args)
+ cb = _format_callback_source(self._callback, self._args)
msg = 'Exception in callback {}'.format(cb)
context = {
'message': msg,
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index 2c741fd..74a99ba 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -162,7 +162,7 @@ class Future:
cb = ''
def format_cb(callback):
- return events._format_callback(callback, ())
+ return events._format_callback_source(callback, ())
if size == 1:
cb = format_cb(cb[0])