Skip to content

Use subclasses instead of patching context-dependent functors

Rosen Matev requested to merge rmatev-loki-context into master

This is a new approach of binding context to functors, which has the following advantages compared to the current version:

  • The scope of each hybrid code evaluation is separate (use a newly created python dictionary each time, given as globals and locals)
  • There is no need for "undecorating", as the original functor classes are not changed. The context-bound subclasses are destroyed automatically once the globals dict is destroyed.
  • The original implementation in !1441 (merged) did not handle properly functors inheriting from other functors, which I noticed while adapting the HLT code.

In addition, I add caching of the expensive reflection that determine if a functor needs to be contextualized. This improves speed of initialization (to about original level).

A few things remain to be done

  • remove the context manager with ..., which is now redundant
  • add standalone test for context-dependent functors. Even if more robust now, the machinery is fragile and we need to spot issues earlier than in Hlt.
  • add a test for nested factories

/cc @ibelyaev @cattanem

Edited by Marco Cattaneo

Merge request reports

Loading