(getter, classes=(tf.Module,))
return stack
Applies the given `getter` when getting members of given `classes`.
Applies the given `getter` when getting members of given `classes`.
Applies the given getter when getting members of given classes .
def _custom_getter(getter, classes=(tf.Module,)):
  """Applies the given `getter` when getting members of given `classes`."""
  # Adapted from
  # https://github.com/deepmind/sonnet/blob/v2/sonnet/src/custom_getter.py#L40.
  stack = contextlib.ExitStack()  # for entering patched contexts
  for cls in classes:
    orig_getattribute = cls.__getattribute__  # pytype: disable=attribute-error

    def new_getattribute(obj, name, orig_getattribute=orig_getattribute):
      attr = orig_getattribute(obj, name)
      return getter(attr)

    stack.enter_context(_patch_getattribute(cls, new_getattribute))
  return stack
def _custom_getter ( getter , classes = ( tf . Module , ) ) : # Adapted from # https://github.com/deepmind/sonnet/blob/v2/sonnet/src/custom_getter.py#L40. stack = contextlib . ExitStack ( ) # for entering patched contexts for cls in classes : orig_getattribute = cls . __getattribute__ # pytype: disable=attribute-error def new_getattribute ( obj , name , orig_getattribute = orig_getattribute ) : attr = orig_getattribute ( obj , name ) return getter ( attr ) stack . enter_context ( _patch_getattribute ( cls , new_getattribute ) ) return stack