Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Inconsistent attribute access in asyncio.coroutine in debug mode
$ python3 --version
Python 3.4.3
$ python3
f result
Traceback (most recent call last):
File "", line 21, in <module>
File "/usr/lib/python3.4/asyncio/", line 154, in wrapper
w.__name__ = func.__name__
File "/usr/lib/python3.4/unittest/", line 570, in __getattr__
raise AttributeError(name)
AttributeError: __name__
Exception ignored in: $
import asyncio
import contextlib
from unittest.mock import Mock
def f():
return "f result"
if __name__ == "__main__":
loop = asyncio.get_event_loop()
with contextlib.closing(loop):
mocked_f = Mock(wraps=f)
# Mocked function doesn't have special attributes like "__name__"
assert not hasattr(mocked_f, "__name__")
# In Python 3.4 with PYTHONASYNCIODEBUG asyncio.coroutine tries to get
# mocked_f.__name__, which leads to error (looks like this behaviour is
# fixed in Python 3.5).
# Without PYTHONASYNCIODEBUG all works as expected.
coro_func = asyncio.coroutine(mocked_f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.