[New-bugs-announce] [issue25648] asyncio.coroutine fails if asyncio debug mode is enabled and wrapped function don't have "__name__" attribute

Vladimir Rutsky report at bugs.python.org
Tue Nov 17 07:47:20 EST 2015


New submission from Vladimir Rutsky:

In Python 3.4.3 with enabled asyncio debug a function is
wrapped using the following code in @asyncio.coroutine:

@functools.wraps(func)
def wrapper(*args, **kwds):
    w = CoroWrapper(coro(*args, **kwds), func)
    if w._source_traceback:
        del w._source_traceback[-1]
    w.__name__ = func.__name__
    if hasattr(func, '__qualname__'):
        w.__qualname__ = func.__qualname__
    w.__doc__ = func.__doc__
    return w

The unconditional access to "__name__" and "__doc__" attributes may fail in some circumstances.

As this case looks strange and unrealistic I met it in a real
application that used mocking in tests. The code there was something like the following:

def f():
    return "f result"

mocked_f = Mock(wraps=f)
coro_func = asyncio.coroutine(mocked_f)
print(loop.run_until_complete(coro_func()))
mocked_f.assert_called_once_with() 

Here is complete example:
https://gist.github.com/rutsky/65cee7728135b05d49c3

This issue is fixed in 95964:957478e95b26 changeset during adding support of async/await syntax, so it is not reproduced in Python 3.5 or 3.4 head, but still reproducible in latest released version of Python 3.4 branch: 3.4.3.

So until 3.4.4 is released this issue still may be considered as not fixed.

----------
components: asyncio
messages: 254800
nosy: gvanrossum, haypo, vrutsky, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.coroutine fails if asyncio debug mode is enabled and wrapped function don't have "__name__" attribute
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25648>
_______________________________________


More information about the New-bugs-announce mailing list