Decorator cllass hides docstring from doctest?
Duncan Booth
duncan.booth at invalid.invalid
Thu Sep 21 09:13:30 EDT 2006
berthold at despammed.com (Berthold =?iso-8859-15?Q?H=F6llmann?=) wrote:
> Saving the following code to a file and running the code through
> python does not give the expected error. disableling the "@decor" line
> leads to the expected error message. Is this a bug or an overseen
> feature?
>
It's a problem with your implementation of the decorator. In fact it is two
problems: the decorated 'f' is a class instance so doctest ignores it, and
it doesn't have a docstring so doctest ignores it.
If you rewrite the decorator so that the decorated 'f' is still a function
and preserve the docstring then it works as you might expect. e.g.
def decor(f):
def wrapper(*args, **kw):
return f(*args, **kw)
wrapper.__doc__ = f.__doc__
wrapper.__name__ = f.__name__
return wrapper
More information about the Python-list
mailing list