Function __setattr__


def __setattr__(self, name, value)


No description yet.


Lines 72-94 in anyfig/

def __setattr__(self, name, value):
  config_class = type(self).__name__
  # Handle interface values
  old_value = getattr(self, name, None)
  if isinstance(old_value, InterfaceField):
    value = old_value.update_value(name, value, config_class)
  # Raise error if frozen unless we're trying to unfreeze the config
  if getattr(self, '_frozen', False) and name != '_frozen':
    err_msg = f"Can't set attribute '{name}'. Config object is frozen. Unfreeze the config to make it mutable"
    raise FrozenInstanceError(err_msg)
  # Check for reserved names
  name_taken_msg = (
    f"The attribute '{name}' can't be assigned to config '{config_class}' since it already has a method by that name"
  methods = inspect.getmembers(self, predicate=inspect.ismethod)
  for method in methods:
    assert name != method[0], name_taken_msg
  object.__setattr__(self, name, value)

Add Discussion as Guest

Log in