def _wrap_variable_creation(func, custom_getter):
 original_get_variable = tf.get_variable
 def custom_get_variable(*args, **kwargs):
  if hasattr(kwargs, 'custom_getter'):
   raise AttributeError('Custom getters are not supported for optimizee variables.')
  return original_get_variable(custom_getter=custom_getter, *args, **kwargs)
 with mock.patch('tensorflow.get_variable', custom_get_variable):
  return func()

def _wrap_variable_creation ( func , custom_getter ) : original_get_variable = tf . get_variable def custom_get_variable ( * args , ** kwargs ) : if hasattr ( kwargs , 'custom_getter' ) : raise AttributeError ( 'Custom getters are not supported for optimizee variables.' ) return original_get_variable ( custom_getter = custom_getter , * args , ** kwargs ) with mock . patch ( 'tensorflow.get_variable' , custom_get_variable ) : return func ( )
provides a custom getter for all variable creations .