Use Predicate.context to share data between predicates
masterWhen Predicate.test() is invoked, a temporary context (a simple dict) is created. This context is valid only for the duration of that specific invocation. You can use it to cache expensive computations or set flags that subsequent predicates in the same chain can access.
Predicate.context also provides an args attribute containing the original arguments passed to test().
>>> @predicate
... def mypred(a, b):
... value = compute_expensive_value(a)
... mypred.context['value'] = value
... return True
>>> @predicate
... def myotherpred(a, b):
... value = myotherpred.context.get('value')
... if value is not None:
... return do_something_with_value(value)
... else:
... return do_something_without_value()