(config, property_path)
return config_copy
Unset key at property_path in config & return new config.

    config is not mutated.

    property_path is a series of dot separated values.
Unset key at property_path in config & return new config.
Unset key at property_path in config & return new config .
def unset_item_from_config(config, property_path):
    """
    Unset key at property_path in config & return new config.

    config is not mutated.

    property_path is a series of dot separated values.
    """
    path_components = property_path.split(".")

    # Mutate a copy of the config, not config itself
    cur_part = config_copy = deepcopy(config)

    def remove_empty_configs(configuration, path):
        """
        Delete the keys that hold an empty dict.

        This might happen when we delete a config property
        that has no siblings from a multi-level config.
        """
        if not path:
            return configuration
        conf_iter = configuration
        for cur_path in path:
            if conf_iter[cur_path] == {}:
                del conf_iter[cur_path]
                remove_empty_configs(configuration, path[:-1])
            else:
                conf_iter = conf_iter[cur_path]

    for i, cur_path in enumerate(path_components):
        if i == len(path_components) - 1:
            if cur_path not in cur_part:
                raise ValueError(f"{property_path} does not exist in config!")
            del cur_part[cur_path]
            remove_empty_configs(config_copy, path_components[:-1])
            break
        else:
            if cur_path not in cur_part:
                raise ValueError(f"{property_path} does not exist in config!")
            cur_part = cur_part[cur_path]

    return config_copy
def unset_item_from_config ( config , property_path ) : path_components = property_path . split ( "." ) # Mutate a copy of the config, not config itself cur_part = config_copy = deepcopy ( config ) def remove_empty_configs ( configuration , path ) : """
        Delete the keys that hold an empty dict.

        This might happen when we delete a config property
        that has no siblings from a multi-level config.
        """ if not path : return configuration conf_iter = configuration for cur_path in path : if conf_iter [ cur_path ] == { } : del conf_iter [ cur_path ] remove_empty_configs ( configuration , path [ : - 1 ] ) else : conf_iter = conf_iter [ cur_path ] for i , cur_path in enumerate ( path_components ) : if i == len ( path_components ) - 1 : if cur_path not in cur_part : raise ValueError ( f"{property_path} does not exist in config!" ) del cur_part [ cur_path ] remove_empty_configs ( config_copy , path_components [ : - 1 ] ) break else : if cur_path not in cur_part : raise ValueError ( f"{property_path} does not exist in config!" ) cur_part = cur_part [ cur_path ] return config_copy