def _handle_inplace_replacements(document, link, link_ancestors):
    """
    Given a new document, and the link/ancestors it was created,
    determine if we should:

    * Make an inline replacement and then return the modified document tree.
    * Return the new document as-is.
    """
    if not link.transform:
        if ('put', 'patch', 'delete') in link.action.lower():
            transform = 'inplace'
        else:
            transform = 'new'
    else:
        transform = link.transform

    if transform == 'inplace':
        root = link_ancestors[0].document
        keys_to_link_parent = link_ancestors[-1].keys
        if document is None:
            return root.delete_in(keys_to_link_parent)
        return root.set_in(keys_to_link_parent, document)

    return document
dataset/ETHPy150Open core-api/python-client/coreapi/transports/http.py/_handle_inplace_replacements/swapped operands of `in`