Author: ianb
Date: 2008-12-10 21:40:56 -0700 (Wed, 10 Dec 2008)
New Revision: 3725

Modified:
   FormEncode/trunk/formencode/schema.py
   FormEncode/trunk/tests/test_schema.py
Log:
Set SimpleFormValidator.__doc__ more generally

Modified: FormEncode/trunk/formencode/schema.py
===================================================================
--- FormEncode/trunk/formencode/schema.py       2008-12-11 04:08:21 UTC (rev 
3724)
+++ FormEncode/trunk/formencode/schema.py       2008-12-11 04:40:56 UTC (rev 
3725)
@@ -434,6 +434,9 @@
 
     validate_partial_form = False
 
+    def __initargs__(self, new_attrs):
+        self.__doc__ = getattr(self.func, '__doc__', None)
+
     def to_python(self, value_dict, state):
         # Since we aren't really supposed to modify things in-place,
         # we'll give the validation function a copy:
@@ -457,12 +460,7 @@
 
     def decorate(cls, **kw):
         def decorator(func):
-            result = cls(func, **kw)
-            try:
-                result.__doc__ = func.__doc__
-            except:
-                pass
-            return result
+            return cls(func, **kw)
         return decorator
 
     decorate = classmethod(decorate)

Modified: FormEncode/trunk/tests/test_schema.py
===================================================================
--- FormEncode/trunk/tests/test_schema.py       2008-12-11 04:08:21 UTC (rev 
3724)
+++ FormEncode/trunk/tests/test_schema.py       2008-12-11 04:40:56 UTC (rev 
3725)
@@ -1,5 +1,5 @@
 from formencode import validators, foreach
-from formencode.schema import Schema, merge_dicts
+from formencode.schema import Schema, merge_dicts, SimpleFormValidator
 from formencode.api import *
 from formencode.variabledecode import NestedVariables
 import cgi
@@ -171,3 +171,19 @@
         pass
     else:
         assert 0
+
+def test_SimpleFormValidator_doc():
+    """
+    Verify SimpleFormValidator preserves the decorated function's
+    docstring.
+    """
+
+    BOGUS_DOCSTRING = "blah blah blah"
+
+    def f(value_dict, state, validator):
+       value_dict['f'] = 99
+
+    f.__doc__ = BOGUS_DOCSTRING
+    g = SimpleFormValidator(f)
+
+    assert f.__doc__ == g.__doc__, "Docstrings don't match!"


------------------------------------------------------------------------------
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/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to