(cls, new_getattribute)
Patch the `__getattribute__` method of `cls` with `new_getattribute`.
Patch the `__getattribute__` method of `cls` with `new_getattribute`.
Patch the __getattribute__ method of cls with new_getattribute .
def _patch_getattribute(cls, new_getattribute):
  """Patch the `__getattribute__` method of `cls` with `new_getattribute`."""
  # Adapted from
  # https://github.com/deepmind/sonnet/blob/v2/sonnet/src/custom_getter.py#L31.
  old_getattribute = cls.__getattribute__  # pytype: disable=attribute-error
  cls.__getattribute__ = new_getattribute
  try:
    yield
  finally:
    cls.__getattribute__ = old_getattribute
def _patch_getattribute ( cls , new_getattribute ) : # Adapted from # https://github.com/deepmind/sonnet/blob/v2/sonnet/src/custom_getter.py#L31. old_getattribute = cls . __getattribute__ # pytype: disable=attribute-error cls . __getattribute__ = new_getattribute try : yield finally : cls . __getattribute__ = old_getattribute