New submission from Szieberth Ádám: I faced this particular issue by writing decorators for asyncio coroutines.
I even posted a question to SO: http://stackoverflow.com/questions/23015626/how-to-decorate-an-asyncio-coroutine-to-retain-its-name However, since that I realized the problem is more general. I believe that a generator object should inherit its function's __name__ attribute instead of ignoring it. Example: ################################################################ import functools def decorated(genfunc): @functools.wraps(genfunc) def wrapper(*args, **kargs): print('inside wrapper') for x in genfunc(*args, **kargs): yield 'decorated: {!r}'.format(x) print('outside wrapper') print('wrapper.__name__: {!r}'.format(wrapper.__name__)) return wrapper @decorated def simple_genfunc(): """Testdoc.""" yield from range(10) if __name__ == '__main__': print('simple_genfunc.__name__: {!r}'.format( simple_genfunc.__name__)) print('simple_genfunc().__name__: {!r}'.format( simple_genfunc().__name__)) ################################################################ And its result: Z:\>python -i genfuncdec.py outside wrapper wrapper.__name__: 'simple_genfunc' simple_genfunc.__name__: 'simple_genfunc' simple_genfunc().__name__: 'wrapper' >>> simple_genfunc <function simple_genfunc at 0x00C30420> >>> simple_genfunc.__wrapped__ <function simple_genfunc at 0x00C304B0> >>> simple_genfunc() <generator object wrapper at 0x00C0EE18> >>> simple_genfunc.__wrapped__() <generator object simple_genfunc at 0x00C0ED28> As you can see the generator object's __name__ remained the hardcoded one. ---------- messages: 215968 nosy: SzieberthAdam priority: normal severity: normal status: open title: Unable to make decorated generator object to inherit generator function's __name__ type: enhancement versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21205> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com