import configparser


def update_config(config_path: str, configs: configparser.ConfigParser,
                  config_name: str, new_val: str):
    """ Updates a configurable property to a new value

    Update a configurable property to the user-provided value. This function
    will also save the updated configurations to the file as well as return
    the updated configurations for additional use, if needed.

    Args:
        config_path: Path to the config.cfg file
        configs: Old script configurations
        config_name: Configuration property to update
        new_val: New value of the configuration property

    Returns:
        configs: Updated script configurations

    """
    if config_name in {"backend", "data_directory"}:
        section = "GENERAL"
    else:
        section = "SQL"
    configs[section][config_name] = new_val
    with open(config_path, "w") as config_file:
        configs.write(config_file)
    return(configs)