##// END OF EJS Templates
use canning hook in dependent...
MinRK -
Show More
@@ -59,10 +59,12 b' class dependent(object):'
59 59 self.df = df
60 60 self.dargs = dargs
61 61 self.dkwargs = dkwargs
62
63 def __call__(self, *args, **kwargs):
62
63 def check_dependency(self):
64 64 if self.df(*self.dargs, **self.dkwargs) is False:
65 65 raise UnmetDependency()
66
67 def __call__(self, *args, **kwargs):
66 68 return self.f(*args, **kwargs)
67 69
68 70 if not py3compat.PY3:
@@ -64,7 +64,7 b' class CannedObject(object):'
64 64 obj = self.obj
65 65 for key in self.keys:
66 66 setattr(obj, key, uncan(getattr(obj, key), g))
67
67
68 68 if self.hook:
69 69 self.hook = uncan(self.hook, g)
70 70 self.hook(obj, g)
@@ -308,6 +308,11 b' def uncan_sequence(obj, g=None):'
308 308 else:
309 309 return obj
310 310
311 def _uncan_dependent_hook(dep, g=None):
312 dep.check_dependency()
313
314 def can_dependent(obj):
315 return CannedObject(obj, keys=('f', 'df'), hook=_uncan_dependent_hook)
311 316
312 317 #-------------------------------------------------------------------------------
313 318 # API dictionaries
@@ -316,7 +321,7 b' def uncan_sequence(obj, g=None):'
316 321 # These dicts can be extended for custom serialization of new objects
317 322
318 323 can_map = {
319 'IPython.parallel.dependent' : lambda obj: CannedObject(obj, keys=('f','df')),
324 'IPython.parallel.dependent' : can_dependent,
320 325 'numpy.ndarray' : CannedArray,
321 326 FunctionType : CannedFunction,
322 327 bytes : CannedBytes,
General Comments 0
You need to be logged in to leave comments. Login now