A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-August/047827.html below:

[Python-Dev] Decorators and docstrings

[Python-Dev] Decorators and docstringsHans Nowak hans at zephyrfalcon.org
Sun Aug 15 04:26:09 CEST 2004
Hi,

When playing with the decorators in 2.4a2, I saw the following behavior:

# wraps an object with the function, and prints this object
# when the function is called.
 >>> def wrapwith(obj):
...     def decorator(f):
...         def _wrapper(*args, **kwargs):
...             print "##", obj
...             return f(*args, **kwargs)
...         return _wrapper
...     return decorator
...
 >>> @wrapwith("hello")
... def foo(x, y):
...     """ foo! """
...     return 2*x + y
...
 >>> foo(4, 5)
## hello
13
 >>> foo.__doc__
 >>>

I.e. if you wrap the function foo with the decorator, it loses the docstring. 
foo.__doc__ is empty.

Is this behavior intended?  Should the decorator in question (in this case, 
'wrapwith') take care of copying of the docstring itself?  Or should the 
decorator mechanism do this automatically (if possible)?

Thanks,

--
Hans Nowak (hans at zephyrfalcon.org)
http://zephyrfalcon.org/

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4