def _set_value(self, key: Text, value: JsonAtomicValue, debug_filename: Text,
                 debug_orig_key: Text):
    """Sets the value of a key-value pair, recursively traversing namespaces."""
    # Detect if this key has a namespace prefix.
    # If so, strip it and recursively delegate to corresponding child object.
    key_parts = key.split(".", 1)
    field_name = key_parts[0]

    # Allow deprecated fields to be suffixed with an underscore.
    if (field_name not in self._field_names and
        "deprecated_" + field_name in self._field_names):
      field_name = "deprecated_" + field_name

    if field_name not in self._field_names:
      error_msg = (f"Config field '{field_name}' is not defined in class "
                   f"'{type(self).__name__}' (specified key='{debug_orig_key}';"
                   f" defined keys=[{','.join(self._field_names)}])")
      if debug_filename:
        error_msg += f" (see file '{debug_filename}')"
      raise ValueError(error_msg)

    if len(key_parts) == 2:
      subkey = key_parts[1]
      child = getattr(self, field_name)
      if not isinstance(child, Config):
        raise ValueError(f"Expected `{debug_orig_key}` to be a `Config` class "
                         f"but found '{type(child).__name__}'")
      value = self._cast_value(target=child, value=value)
      # pylint: disable=protected-access
      child._set_value(
          subkey,
          value,
          debug_filename=debug_filename,
          debug_orig_key=debug_orig_key)
      # pylint: enable=protected-access
      return

    target = getattr(self, field_name)
    value = self._cast_value(target=target, value=value)

    # Otherwise, we're at the base case and can directly set the attribute.
    assert len(key_parts) == 1
    setattr(self, key, value)
Sets the value of a key-value pair, recursively traversing namespaces.
language/canine/config_utils.py