functions and functional programming to fix thiswrite decorator functions so that they propagate the function name and documentation string for exampledef wrap(func)call(*args,**kwargs)return func(*args,**kwargscall _doc_ func _doc_ call _name_ func _name_ return call because this is common problemthe functools module provides function wraps that can automatically copy these attributes not surprisinglyit is also decoratorfrom functools import wraps def wrap(func)@wraps(funccall(*args,**kwargs)return func(*args,**kwargsreturn call the @wraps(funcdecoratordefined in functoolspropagates attributes from func to the wrapper function that is being defined function attributes functions can have arbitrary attributes attached to them here' an exampledef foo()statements foo secure foo private function attributes are stored in dictionary that is available as the __dict__ attribute of function the primary use of function attributes is in highly specialized applications such as parser generators and application frameworks that would like to attach additional information to function objects as with documentation stringscare should be given if mixing function attributes with decorators if function is wrapped by decoratoraccess to the attributes will actually take place on the decorator functionnot the original implementation this may or may not be what you want depending on the application to propagate already defined function attributes to decorator functionuse the following template or the functools wraps(decorator as shown in the previous sectiondef wrap(func)call(*args,**kwargs)return func(*args,**kwargscall _doc_ func _doc_ call _name_ func _name_ call _dict_ update(func _dict_ _return call lib fl ff