def merge_dicts(srcdict: dict, mergedict: dict, overwrite=False):
    """Recursively merges `mergedict` into `srcdict` and returns `srcdict`.

    Makes shallow copies of `dict` and `list` values.
    """
    for k, v in mergedict.items():
        srcvalue = srcdict.get(k, None)

        if isinstance(v, dict) and isinstance(srcvalue, dict):
            merge_dicts(srcvalue, v, overwrite)
            continue

        if overwrite or srcvalue is None:
            if isinstance(v, dict):
                v = dict(v)
            elif isinstance(v, list):
                v = list(v)
            srcdict[k] = v

    return srcdict