diff --git a/docs/changes.rst b/docs/changes.rst index 03d7ba1b..3de2c81e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -11,6 +11,13 @@ Version 1.12.0 to access the true type of the base class using ``__wrapped__`` in the inherited class list of the derived class. +**Bugs Fixed** + +* When using the ``synchronized`` decorator on instance methods of a + class, if the class declared special methods to override the result for + when the class instance was tested as a boolean so that it returned + ``False`` all the time, the synchronized method would fail when called. + Version 1.11.2 -------------- diff --git a/tests/test_synchronized_lock.py b/tests/test_synchronized_lock.py index af654d43..6e7eb12d 100644 --- a/tests/test_synchronized_lock.py +++ b/tests/test_synchronized_lock.py @@ -55,6 +55,18 @@ def function3(): c4 = C4() +class C5(object): + + def __bool__(self): + return False + __nonzero__=__bool__ + + @wrapt.synchronized + def function1(self): + print('function1') + +c5 = C5() + class TestSynchronized(unittest.TestCase): def test_synchronized_function(self): @@ -261,5 +273,16 @@ def test_synchronized_type_old_style(self): self.assertNotEqual(_lock3, None) self.assertEqual(_lock3, _lock2) + def test_synchronized_false_instance(self): + c5.function1() + + self.assertEqual(bool(c5), False) + + _lock1 = getattr(C5, '_synchronized_lock', None) + self.assertEqual(_lock1, None) + + _lock2 = getattr(c5, '_synchronized_lock', None) + self.assertNotEqual(_lock2, None) + if __name__ == '__main__': unittest.main()