doctests and decorators
Scott David Daniels
Scott.Daniels at Acm.Org
Tue Jun 16 14:09:35 EDT 2009
Eric Snow wrote:
> ...
> One work-around I found is the following change in example:
> test1.py
> ++++++++++++++++++++++++++++
> def decorator(function):
> def new_function(*args, **kwargs):
> return function(*args, **kwargs)
> new_function.__module__ = function.__module__
> new_function.__doc__ = function.__doc__
> new_function.__name__ = function.__name__
> return new_function
>
> However, this seems pretty lame. The doctest module should be able to
> figure out that the docstring belongs is there in the module.
would the following look better?
import functools
...
def decorator(function):
@functools.wraps(function)
def new_function(*args, **kwargs):
return function(*args, **kwargs)
return new_function
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list