Beispiel #1
0
 def wrapped_fn(self, *args, **kwargs):
   fn_name = class_fn.__name__
   method_suffix = f'.{fn_name}' if fn_name != '__call__' else ''
   module_name = self.name or self.__class__.__name__
   full_name = f'{module_name}{method_suffix}'
   # make a scope-function to transform
   def core_fn(scopes, *args, **kwargs):
     cloned = set_module_scopes(self, scopes)
     cloned._state = self._state.export()  # pylint: disable=protected-access
     res = prewrapped_fn(cloned, *args, **kwargs)
     self._state.reimport(cloned._state)  # pylint: disable=protected-access
     return res
   # here we apply the given lifting transform to the scope-ingesting fn
   trafo_fn = lift.named_call(core_fn, full_name)
   return trafo_fn(get_module_scopes(self), *args, **kwargs)
Beispiel #2
0
    def wrapped_fn(self, *args, **kwargs):
        fn_name = class_fn.__name__
        method_suffix = f'.{fn_name}' if fn_name != '__call__' else ''
        module_name = self.name or self.__class__.__name__
        full_name = f'{module_name}{method_suffix}'

        # make a scope-function to transform
        def core_fn(scopes, *args, **kwargs):
            cloned = set_module_scopes(self, scopes)
            res = rewrapped_fn(cloned, *args, **kwargs)
            # preserve submodule-tree stripped of scopes/tracers for introspection
            object.__setattr__(self, 'children', clean_clone(cloned).children)
            return res

        # here we apply the given lifting transform to the scope-ingesting fn
        trafo_fn = lift.named_call(core_fn, full_name)
        return trafo_fn(get_module_scopes(self), *args, **kwargs)