def _dotted_set(
        self, dotted_key, value, tomlfy=False, validate=empty, **kwargs
    ):
        """Sets dotted keys as nested dictionaries.

        Dotted set will always reassign the value, to merge use `@merge` token

        Arguments:
            dotted_key {str} -- A traversal name e.g: foo.bar.zaz
            value {Any} -- The value to set to the nested value.

        Keyword Arguments:
            tomlfy {bool} -- Perform toml parsing (default: {False})
            validate {bool} --
        """
        if validate is empty:
            validate = self.get(
                "VALIDATE_ON_UPDATE_FOR_DYNACONF"
            )  # pragma: nocover

        # Add a "." before "[" to help splitting
        split_keys = dotted_key.replace("[", ".[").split(".")
        existing_data = self.get(split_keys[0], {})
        if self.get("DYNABOXIFY", True):
            new_data = tree = DynaBox(box_settings=self)
        else:
            new_data = tree = {}
        value = parse_conf_data(value, tomlfy=tomlfy, box_settings=self)

        for n, k in enumerate(split_keys):
            is_not_end = n < (len(split_keys) - 1)
            if is_not_end:
                next_default = [] if "[" in split_keys[n + 1] else {}

            if "[" not in k:  # accessing field of a dict
                if is_not_end:
                    tree = tree.setdefault(k, next_default)  # get next
                else:
                    tree[k] = value  # assign value
            elif k.startswith("[") and k.endswith(
                "]"
            ):  # accessing index of a list
                index = int(k.replace("[", "").replace("]", ""))
                # This makes sure we can assign any arbitrary index
                tree.extend([next_default] * (index + 1))
                if is_not_end:
                    tree = tree[index]  # get at index
                else:
                    tree[index] = value  # assign value
            else:  # odd cases like [2]0
                raise (ValueError("Invalid field:", k))

        if existing_data:
            if self.get("DYNABOXIFY", True):
                old_data = DynaBox(
                    {split_keys[0]: existing_data}, box_settings=self
                )
            else:
                old_data = {split_keys[0]: existing_data}

            new_data = object_merge(
                old=old_data,
                new=new_data,
                full_path=split_keys,
                list_merge="deep",  # when to use deep / shallow replace?
            )
        self.update(data=new_data, tomlfy=tomlfy, validate=validate, **kwargs)
Sets dotted keys as nested dictionaries.

        Dotted set will always reassign the value, to merge use `@merge` token

        Arguments:
            dotted_key {str} -- A traversal name e.g: foo.bar.zaz
            value {Any} -- The value to set to the nested value.

        Keyword Arguments:
            tomlfy {bool} -- Perform toml parsing (default: {False})
            validate {bool} --
        
dynaconf/base.py