import http


def _id_matches(entity, id_field, path_id):
    """Checks if the ID field of an entity agrees with the ID specified in the
    URL as a path variable.

    Args:
        entity: Entity as a dict.
        id_field: Name of the ID field as a string.
        path_id: ID specified as a path variable in the URL, as a string. This
            is optional. If None, the function does not perform the check.

    Returns:
        See module docstring.
    """
    entity_id = entity.get(id_field, path_id)
    if path_id and path_id != entity_id:
        return (False, f'{id_field} {path_id} in path variable does not match '
                f'{id_field} {entity_id} in request body ',
                http.HTTPStatus.CONFLICT)
    return True, None, None