diff options
author | Guido van Rossum <guido@python.org> | 2015-05-03 01:38:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2015-05-03 01:38:24 (GMT) |
commit | 0a9933ebf3704540a5f31225b26acb990e1de4bf (patch) | |
tree | aabc7b609ae15cc12bf49cd4451122d2c661c471 /Lib/asyncio/coroutines.py | |
parent | 4590c3d944230aff3d1e6810d3113e790922359c (diff) | |
download | cpython-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/coroutines.py')
-rw-r--r-- | Lib/asyncio/coroutines.py | 18 |
1 files changed, 12 insertions, 6 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 |