summaryrefslogtreecommitdiff
path: root/asyncio/coroutines.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2015-04-14 16:38:17 +0200
committerVictor Stinner <vstinner@redhat.com>2015-04-14 16:53:00 +0200
commitb08ee4008dc939fff3aa86f040da02deb602f5db (patch)
tree7dd3fdc7272ca72468bb4ec2a037882d8077f700 /asyncio/coroutines.py
parent173ff866346d8210acfa268239aa99d907fc38a2 (diff)
downloadtrollius-git-issue_222.tar.gz
Fix @coroutine for functions without __name__issue_222
Issue #222: Fix the @coroutine decorator for functions without __name__ attribute like functools.partial(). Enhance also the representation of a CoroWrapper if the coroutine function is a functools.partial().
Diffstat (limited to 'asyncio/coroutines.py')
-rw-r--r--asyncio/coroutines.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/asyncio/coroutines.py b/asyncio/coroutines.py
index a1b2875..c639461 100644
--- a/asyncio/coroutines.py
+++ b/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