def is_comprehension(leaf):
    """
    Return true if the leaf is the beginning of a list/set/dict comprehension.
    Returns true for generators as well
    """
    if leaf.type != 'operator' or leaf.value not in {'[', '(', '{'}:
        return False

    sibling = leaf.get_next_sibling()

    return (sibling.type in {'testlist_comp', 'dictorsetmaker'}
            and sibling.children[-1].type == 'sync_comp_for')