human
I wrote the below code

    if (not (name or tvdb_id)):
        raise LookupError(u'No    criteria    specified    for    tvdb    lookup')
    log.debug(u"Looking    up    tvdb    information    for    '%s'.    TVDB    ID:    %s", name, tvdb_id)
    series = None
    def id_str():
        return (u'<name=%s,tvdb_id=%s>' % (name, tvdb_id))
    if tvdb_id:
        series = session.query(TVDBSeries).filter((TVDBSeries.id == tvdb_id)).first()
    if ((not series) and name):
        found = session.query(TVDBSearchResult).filter((TVDBSearchResult.search == name.lower())).first()
        if (found and found.series):
            series = found.series
    if series:
        if (not only_cached):
            mark_expired(session)
        if ((not only_cached) and series.expired):
            log.verbose(u'Data    for    %s    has    expired,    refreshing    from    tvdb', series.name)
            try:
                updated_series = TVDBSeries(series.id, language)
                series = session.merge(updated_series)
                _update_search_strings(series, session, search=name)
            except LookupError as e:
                log.warning(u'Error    while    updating    from    tvdb    (%s),    using    cached    data.', e.args[0])
        else:
            log.debug(u'Series    %s    information    restored    from    cache.', id_str())
    else:
        if only_cached:
            raise LookupError((u'Series    %s    not    found    from    cache' % id_str()))
        log.debug(u'Series    %s    not    found    in    cache,    looking    up    from    tvdb.', id_str())
        if tvdb_id:
            series = session.merge(TVDBSeries(tvdb_id, language))
        elif name:
            tvdb_id = find_series_id(name, language=language)
            if tvdb_id:
                series = session.query(TVDBSeries).filter((TVDBSeries.id == tvdb_id)).first()
                if (not series):
                    series = session.merge(TVDBSeries(tvdb_id, language))
        if (series and series.name):
           ...

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

@with_session
def lookup_series(name=None, tvdb_id=None, only_cached=False, session=None, language=None):