def _deep_annotate(element, annotations, exclude=None):
    def clone(elem):
        if exclude and \
                hasattr(elem, 'proxy_set') and \
                elem.proxy_set.intersection(exclude):
            newelem = elem._clone()
        elif annotations != elem._annotations:
            newelem = elem._annotate(annotations)
        else:
            newelem = elem
        newelem._copy_internals(clone=clone)
        return newelem

    if element is not None:
        element = clone(element)
    return element
Deep copy the given ClauseElement, annotating each element
dataset/ETHPy150Open zzzeek/sqlalchemy/lib/sqlalchemy/sql/annotation.py/_deep_annotate