def find_arg_end(field_name):
    """
    Returns the index of the end of an attribute name or element index.
    field_name:   the field being looked up, e.g. "0.name"
                  or "lookup[3]"
    """
    dot_idx = field_name.find(".")
    lbrack_idx = field_name.find("[")
    if dot_idx == -1:
        return lbrack_idx
    if lbrack_idx == -1:
        return dot_idx
    return min(dot_idx, lbrack_idx)