From 4d43cb062f85c126024a5602ce761326453bdb56 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Thu, 18 May 2017 01:05:36 +0100 Subject: [PATCH 1/2] Exposing inargs and inkwargs as Callable.args and .kwargs --- holoviews/core/spaces.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/holoviews/core/spaces.py b/holoviews/core/spaces.py index bba2f4dc16..eb9966cd67 100644 --- a/holoviews/core/spaces.py +++ b/holoviews/core/spaces.py @@ -458,7 +458,8 @@ def __init__(self, callable, **params): **dict(params, name=util.callable_name(callable))) self._memoized = {} self._is_overlay = False - + self.args = None + self.kwargs = None @property def argspec(self): @@ -485,7 +486,7 @@ def clone(self, callable=None, **overrides): def __call__(self, *args, **kwargs): # Nothing to do for callbacks that accept no arguments - (inargs, inkwargs) = (args, kwargs) + (self.args, self.kwargs) = (args, kwargs) if not args and not kwargs: return self.callable() inputs = [i for i in self.inputs if isinstance(i, DynamicMap)] streams = [] @@ -518,8 +519,8 @@ def __call__(self, *args, **kwargs): try: ret = self.callable(*args, **kwargs) except: - posstr = ', '.join(['%r' % el for el in inargs]) if inargs else '' - kwstr = ', '.join('%s=%r' % (k,v) for k,v in inkwargs.items()) + posstr = ', '.join(['%r' % el for el in self.args]) if self.args else '' + kwstr = ', '.join('%s=%r' % (k,v) for k,v in self.kwargs.items()) argstr = ', '.join([el for el in [posstr, kwstr] if el]) message = ("Exception raised in callable '{name}' of type '{ctype}'.\n" "Invoked as {name}({argstr})") From 97b752de8a24cd34c3e1a2e8ba6783f5a4ade378 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Thu, 18 May 2017 01:13:30 +0100 Subject: [PATCH 2/2] Added four simple unit tests of the .args and .kwargs attributes --- tests/testcallable.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/testcallable.py b/tests/testcallable.py index e3c4c55b44..fa4d90c06a 100644 --- a/tests/testcallable.py +++ b/tests/testcallable.py @@ -198,6 +198,27 @@ def mixed_example(a,b, c=10, d=20): self.assertEqual(Callable(mixed_example)(3,5,5), 33) +class TestLastArgsKwargs(ComparisonTestCase): + + def test_args_none_before_invocation(self): + c = Callable(lambda x,y: x+y) + self.assertEqual(c.args, None) + + def test_kwargs_none_before_invocation(self): + c = Callable(lambda x,y: x+y) + self.assertEqual(c.kwargs, None) + + def test_args_invocation(self): + c = Callable(lambda x,y: x+y) + c(1,2) + self.assertEqual(c.args, (1,2)) + + def test_kwargs_invocation(self): + c = Callable(lambda x,y: x+y) + c(x=1,y=4) + self.assertEqual(c.kwargs, dict(x=1,y=4)) + + class TestDynamicMapInvocation(ComparisonTestCase): """ Test that DynamicMap passes kdims and stream parameters correctly to