Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that param watch decorator is resolved using MRO #327

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should look into these issues.

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