Skip to content

Commit

Permalink
Merge 44de7f0 into 4763c50
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 29, 2019
2 parents 4763c50 + 44de7f0 commit cba6a88
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
20 changes: 11 additions & 9 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,17 +1562,19 @@ def outputs(self_):
index into the output if multiple outputs are returned.
"""
outputs = {}
for name in dir(self_.self_or_cls):
method = getattr(self_.self_or_cls, name)
dinfo = getattr(method, '_dinfo', {})
if 'outputs' not in dinfo:
continue
for override, otype, idx in dinfo['outputs']:
if override is not None:
name = override
outputs[name] = (otype, method, idx)
for cls in classlist(self_.cls):
for name in dir(cls):
method = getattr(self_.self_or_cls, name)
dinfo = getattr(method, '_dinfo', {})
if 'outputs' not in dinfo:
continue
for override, otype, idx in dinfo['outputs']:
if override is not None:
name = override
outputs[name] = (otype, method, idx)
return outputs


def _spec_to_obj(self_,spec):
# TODO: when we decide on spec, this method should be
# rewritten
Expand Down
31 changes: 31 additions & 0 deletions tests/API1/testparamoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,37 @@ def single_output(self):
self.assertEqual(method, p.single_output)
self.assertEqual(idx, None)

def test_subclass_output(self):
class A(param.Parameterized):

@param.output()
def single_output(self):
return 1

class B(param.Parameterized):

@param.output()
def another_output(self):
return 2

class C(A, B):
pass

p = C()
outputs = p.param.outputs()
self.assertEqual(sorted(outputs), ['another_output', 'single_output'])

otype, method, idx = outputs['single_output']
self.assertIs(type(otype), param.Parameter)
self.assertEqual(method, p.single_output)
self.assertEqual(idx, None)

otype, method, idx = outputs['another_output']
self.assertIs(type(otype), param.Parameter)
self.assertEqual(method, p.another_output)
self.assertEqual(idx, None)


def test_named_kwarg_output(self):
class P(param.Parameterized):

Expand Down

0 comments on commit cba6a88

Please sign in to comment.