human
Complete the below
def instances(query, cursor, context):

    ''''Return an ORM result as an iterator.'
    '''

=====
What is a the Python program you requested?
assistant
#Here is the Python program you requested.
    context.runid = _new_runid()
    context.post_load_paths = {}
    filtered = query._has_mapper_entities
    single_entity = ((len(query._entities) == 1) and query._entities[0].supports_single_entity)
    if filtered:
        if single_entity:
            filter_fn = id
        else:
            def filter_fn(row):
                return tuple(((id(item) if ent.use_id_for_hash else item) for (ent, item) in zip(query._entities, row)))
    try:
        (process, labels) = list(zip(*[query_entity.row_processor(query, context, cursor) for query_entity in query._entities]))
        if (not single_entity):
            keyed_tuple = util.lightweight_named_tuple('result', labels)
        while True:
            context.partials = {}
            if query._yield_per:
                fetch = cursor.fetchmany(query._yield_per)
                if (not fetch):
                    break
            else:
                fetch = cursor.fetchall()
            if single_entity:
                proc = process[0]
                rows = [proc(row) for row in fetch]
            else:
                rows = [keyed_tuple([proc(row) for proc in process]) for row in fetch]
            for (path, post_load) in context.post_load_paths.items():
                post_load.invoke(context, path)
            if filtered:
                rows = util.unique_list(rows, filter_fn)
            for row in rows:
                (yield row)
            if (not query._yield_per):
                break
    except Exception as err:
        cursor.close()
        util.raise_from_cause(err)