Re: SimpleFormValidator obscures my docstrings (and doctests!)
Ian Bicking <[email protected]> Wed, 10 Dec 2008 22:09:55 -0600
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
I put a little (untested) fix in trunk, r3724. It just tries to copy
__doc__ over to the instance.
Matthew Wilson wrote:
> I wrote some doctests on a validator, then discovered that decorating
> with SimpleFormValidator means that those doctests are on the inner
> func attribute, not the outer object, so as far as I can tell, I can
> run those doctests.
>
> Trivial example:
>
>>>> @SimpleFormValidator.decorate()
> def f(value_dict, state, validator):
> """
> Add a new key 'f' pointing to 99 to value_dict.
> """
> value_dict['f'] = 99
> ...
>>>> f().to_python({}, None)
> {'f': 99}
>
> Here's the problem: the docstring on the decorated f is really the
> SimpleFormValidator's docstring:
>
>>>> f.__doc__ == SimpleFormValidator.__doc__
> True
>
> Luckilly, the originally docstring is still alive, just hidden inside:
>
>>>> print f.func.__doc__
>
> Add a new key 'f' pointing to 99 to value_dict.
>
> I'm trying to write some doctests for my validator f, but my test
> runner (nose) doesn't run the doctests.
>
> Any ideas about a solution?
>
> Matt
>
>
--
Ian Bicking : [email protected] : http://blog.ianbicking.org
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/