feat: allow callable values in contexts#198
feat: allow callable values in contexts#198tlambert03 wants to merge 1 commit intopyapp-kit:mainfrom
Conversation
|
@lucyleeow @DragaDoncila @Czaki ... let me know if you'd like this feature: it allows this: In [2]: from app_model.expressions import parse_expression
In [3]: expr = parse_expression("x < 10")
In [4]: expr.eval_callable_context({'x': lambda: 42})
Out[4]: Falseessentially, if we made this mode default (or somehow explicitly opt-in), it would allow you to undo the changes made to layer_delegate: https://github.com/napari/napari/blob/4a56237e94480934b1b9f5df5c63949a4059b1f8/napari/_qt/containers/_layer_delegate.py#L325-L328 and instead "permanently" set However, in any case, I still would recommend not calculating |
|
moving to #199 ... accidentally had this on my main branch |
This implements the idea I was mentioning in #196 , wherein a context value is allowed to be a callable (that takes no arguments).
it seems the performance penalty isn't too bad (but of course it would depend on how slow the function is that has to be evaluated to fill in the context: