Skip to content

Commit

Permalink
Add change notes/test for bug in synchronized decorator when applied …
Browse files Browse the repository at this point in the history
…to instance methods of a falsey class.
  • Loading branch information
GrahamDumpleton committed Jan 6, 2020
1 parent d7ab8d8 commit 0c98567
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down
23 changes: 23 additions & 0 deletions tests/test_synchronized_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 0c98567

Please sign in to comment.