def coerce_key_types(doc, keys):
    ret = []
    active = doc
    for idx, key in enumerate(keys):
        # Coerce array lookups to integers.
        if isinstance(active, coreapi.Array):
            try:
                key = int(key)
            except:
                pass

        # Descend through the document, so we can correctly identify
        # any nested array lookups.
        ret.append(key)
        try:
            active = active[key]
        except (KeyError, IndexError, ValueError, TypeError):
            ret += keys[idx + 1:]
            break

    return ret
Given a document and a list of keys such as ['rows', '123', 'edit'],
dataset/ETHPy150Open core-api/python-client/coreapi/commandline.py/coerce_key_types