Skip to content

Commit

Permalink
Un-break wrapping of callable instances as 'colander.deferred'.
Browse files Browse the repository at this point in the history
Fixes #141.
  • Loading branch information
tseaver committed Nov 26, 2014
1 parent da9def7 commit 7a244f1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Unreleased
----------

Bug Fixes
~~~~~~~~~

- Un-break wrapping of callable instances as ``colander.deferred``.
See https://github.com/Pylons/colander/issues/141.

1.0b1 (2013-09-01)
------------------

Expand Down
5 changes: 4 additions & 1 deletion colander/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,10 @@ class deferred(object):
""" A decorator which can be used to define deferred schema values
(missing values, widgets, validators, etc.)"""
def __init__(self, wrapped):
functools.update_wrapper(self, wrapped)
try:
functools.update_wrapper(self, wrapped)
except AttributeError: #non-function
self.__doc__ = getattr(wrapped, '__doc__', None)
self.wrapped = wrapped

def __call__(self, node, kw):
Expand Down
28 changes: 25 additions & 3 deletions colander/tests/test_colander.py
Original file line number Diff line number Diff line change
Expand Up @@ -3045,12 +3045,34 @@ def wrapped(node, kw):
self.assertEqual(result, 'abc')

def test_retain_func_details(self):
def wrapper_func(node, kw):
def wrapped_func(node, kw):
"""Can you hear me now?"""
pass # pragma: no cover
inst = self._makeOne(wrapper_func)
inst = self._makeOne(wrapped_func)
self.assertEqual(inst.__doc__, 'Can you hear me now?')
self.assertEqual(inst.__name__, 'wrapper_func')
self.assertEqual(inst.__name__, 'wrapped_func')

def test_w_callable_instance_no_name(self):
from colander import deferred
class Wrapped(object):
"""CLASS"""
def __call__(self, node, kw):
"""METHOD"""
pass # pragma: no cover
wrapped = Wrapped()
inst = self._makeOne(wrapped)
self.assertEqual(inst.__doc__, wrapped.__doc__)
self.assertFalse('__name__' in inst.__dict__)

def test_w_callable_instance_no_name_or_doc(self):
from colander import deferred
class Wrapped(object):
def __call__(self, node, kw):
pass # pragma: no cover
wrapped = Wrapped()
inst = self._makeOne(wrapped)
self.assertEqual(inst.__doc__, None)
self.assertFalse('__name__' in inst.__dict__)

class TestSchema(unittest.TestCase):
def test_alias(self):
Expand Down

0 comments on commit 7a244f1

Please sign in to comment.