def dict_assign(obj, key, value):
    """Chainable dictionary assignment. Returns a copy.

    Parameters
    ----------
    obj : dict
        A dictionary
    key : string
        Which attribute to set. May be a new attribute, or overwriting an existing one
    value
        A value of any type

    Returns
    -------
    dict
        A new dictionary, with the given attribute set to the given value

    """
    new_dict = dict(obj)
    new_dict[key] = value
    return new_dict