human
I wrote the below code

    def lookup_by_id_or_name(self, ref, before=None):
        u'\n                                Given    an    key    *ref*,    finds    the    first    element    in    the    iterator\n                                with    the    attribute    ID    ==    *ref*    or    name    ==    *ref*.        If    *before*\n                                is    provided,    will    stop    searching    at    the    object    *before*.        This\n                                is    important,    since    "forward    references"    are    not    allowed    in\n                                the    VOTABLE    format.\n                                '
        for element in getattr(self, iterator)():
            if (element is before):
                if (ref in (element.ID, element.name)):
                    vo_raise(u'{}    references    itself'.format(element_name), element._config, element._pos, KeyError)
                break
            if (ref in (element.ID, element.name)):
                return element
        raise KeyError(u"No    {}    with    ID    or    name    '{}'    found    before    the    referencing    {}".format(element_name, ref, element_name))
    lookup_by_id_or_name.__doc__ = doc
    return lookup_by_id_or_name

What's a good function header?
assistant
#Here's a good function header.

def _lookup_by_id_or_name_factory(iterator, element_name, doc):