def set(
        self,
        key,
        value,
        loader_identifier: SourceMetadata | str | None = None,
        tomlfy=False,
        dotted_lookup=empty,
        is_secret="DeprecatedArgument",  # noqa
        validate=empty,
        merge=empty,
    ):
        """Set a value storing references for the loader

        :param key: The key to store. Can be of any type.
        :param value: The raw value to parse and store
        :param loader_identifier: Optional loader name e.g: toml, yaml etc.
                                  Or instance of SourceMetadata
        :param tomlfy: Bool define if value is parsed by toml (defaults False)
        :param merge: Bool define if existing nested data will be merged.
        :param validate: Bool define if validation will be triggered
        """

        # Ensure source_metadata always is set even if set is called
        # without a loader_identifier
        if isinstance(loader_identifier, str) or loader_identifier is None:
            source_metadata = SourceMetadata(
                loader="set_method",
                identifier=loader_identifier or "undefined",
                merged=merge is True,
            )
        else:  # loader identifier must be a SourceMetadata instance
            source_metadata = loader_identifier

        if validate is empty:
            validate = self.get("VALIDATE_ON_UPDATE_FOR_DYNACONF")
        if dotted_lookup is empty:
            dotted_lookup = self.get("DOTTED_LOOKUP_FOR_DYNACONF")

        # Do index replacement first
        nested_ind = self.get("INDEX_SEPARATOR_FOR_DYNACONF")
        # DYNACONF_DATA__a___0__key___2__subkey ->
        # DYNACONF_DATA__a[0]__key[2]__subkey
        if nested_ind and isinstance(key, str):
            nested_ind = rf"{nested_ind}(\d+)"
            key = re.sub(nested_ind, r"[\1]", key)

        nested_sep = self.get("NESTED_SEPARATOR_FOR_DYNACONF")

        if isinstance(key, str):
            if nested_sep and nested_sep in key:
                key = key.replace(nested_sep, ".")  # FOO__bar -> FOO.bar

            if ("." in key or "[" in key) and dotted_lookup is True:
                return self._dotted_set(
                    key,
                    value,
                    loader_identifier=source_metadata,
                    tomlfy=tomlfy,
                    validate=validate,
                )
            key = upperfy(key.strip())

        parsed = parse_conf_data(value, tomlfy=tomlfy, box_settings=self)

        # Fix for #869 - The call to getattr trigger early evaluation
        existing = (
            self.store.get(key, None) if not isinstance(parsed, Lazy) else None
        )

        if getattr(parsed, "_dynaconf_insert", False):
            # `@insert` calls insert in a list by index
            if existing and isinstance(existing, list):
                source_metadata = source_metadata._replace(merged=True)
                existing.insert(parsed.index, parsed.unwrap())
                parsed = existing
            else:
                parsed = [parsed.unwrap()]

        if getattr(parsed, "_dynaconf_del", None):
            self.unset(key, force=True)  # `@del` in a first level var.
            return

        if getattr(parsed, "_dynaconf_reset", False):  # pragma: no cover
            parsed = parsed.unwrap()  # `@reset` in a first level var.

        if getattr(parsed, "_dynaconf_merge_unique", False):
            # `@merge_unique` in a first level var
            if existing:
                # update SourceMetadata (for inspecting purposes)
                source_metadata = source_metadata._replace(merged=True)
                parsed = object_merge(existing, parsed.unwrap(), unique=True)
            else:
                parsed = parsed.unwrap()

        if getattr(parsed, "_dynaconf_merge", False):
            # `@merge` in a first level var
            if existing:
                # update SourceMetadata (for inspecting purposes)
                source_metadata = source_metadata._replace(merged=True)
                parsed = object_merge(existing, parsed.unwrap())
            else:
                parsed = parsed.unwrap()

        should_merge = existing is not None and existing != parsed
        if should_merge:
            # `dynaconf_merge` used in file root `merge=True`
            if merge and merge is not empty:
                source_metadata = source_metadata._replace(merged=True)
                parsed = object_merge(existing, parsed)
            else:
                # `dynaconf_merge` may be used within the key structure
                # Or merge_enabled is set to True
                parsed, source_metadata = self._merge_before_set(
                    existing,
                    parsed,
                    source_metadata,
                    context_merge=merge,
                    list_merge="replace"
                    if source_metadata
                    and source_metadata.loader == "setdefault"
                    and source_metadata.env == "development"
                    else "merge",  # fix 905
                )

        if (
            self.get("DYNABOXIFY", True)
            and isinstance(parsed, dict)
            and not isinstance(parsed, DynaBox)
        ):
            parsed = DynaBox(parsed, box_settings=self)

        # Set the parsed value
        self.store[key] = parsed
        self._deleted.discard(key)

        # check if str because we can't directly set/get non-str with obj. e.g.
        #     setting.1
        #     settings.(1,2)
        if isinstance(key, str):
            super().__setattr__(key, parsed)

        # Track history for inspect, store the raw_value
        if source_metadata in self._loaded_by_loaders:
            self._loaded_by_loaders[source_metadata][key] = value
        else:
            self._loaded_by_loaders[source_metadata] = {key: value}

        if loader_identifier is None:
            # if .set is called without loader identifier it becomes
            # a default value and goes away only when explicitly unset
            self._defaults[key] = parsed

        if validate is True:
            self.validators.validate()
Set a value storing references for the loader

        :param key: The key to store. Can be of any type.
        :param value: The raw value to parse and store
        :param loader_identifier: Optional loader name e.g: toml, yaml etc.
                                  Or instance of SourceMetadata
        :param tomlfy: Bool define if value is parsed by toml (defaults False)
        :param merge: Bool define if existing nested data will be merged.
        :param validate: Bool define if validation will be triggered
        
dynaconf/base.py