Skip to content

Commit

Permalink
Ensure that param watch decorator is resolved using MRO (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Mar 15, 2019
1 parent 98eb32a commit 4763c50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 11 additions & 8 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -2246,14 +2246,17 @@ def __init__(self,**params):
object_count += 1

# add watched dependencies
for n in self.__class__.param._depends['watch']:
# TODO: should improve this - will happen for every
# instantiation of Parameterized with watched deps. Will
# probably store expanded deps on class - see metaclass
# 'dependers'.
for p in self.param.params_depended_on(n):
# TODO: can't remember why not just pass m (rather than _m_caller) here
(p.inst or p.cls).param.watch(_m_caller(self,n),p.name,p.what)
for cls in classlist(self.__class__):
if not issubclass(cls, Parameterized):
continue
for n in cls.param._depends['watch']:
# TODO: should improve this - will happen for every
# instantiation of Parameterized with watched deps. Will
# probably store expanded deps on class - see metaclass
# 'dependers'.
for p in self.param.params_depended_on(n):
# TODO: can't remember why not just pass m (rather than _m_caller) here
(p.inst or p.cls).param.watch(_m_caller(self,n),p.name,p.what)

self.initialized=True

Expand Down
12 changes: 12 additions & 0 deletions tests/API1/testwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def _set_d_bounds(self):
self.param.d.bounds = (self.c, self.c*2)


class WatchSubclassExample(WatchMethodExample):

pass



class TestWatch(API1TestCase):

Expand Down Expand Up @@ -451,6 +456,13 @@ def test_multiple_watcher_dispatch_on_param_attribute(self):
self.assertEqual(obj.param.d.bounds, (2, 4))
self.assertEqual(accumulator.call_count(), 1)

def test_depends_with_watch_on_subclass(self):
obj = WatchSubclassExample()

obj.b = 3
self.assertEqual(obj.c, 6)




class TestWatchValues(API1TestCase):
Expand Down

0 comments on commit 4763c50

Please sign in to comment.