def METHOD_NAME(heap):
    assert_heap_type(heap)
    def hq_heappop_impl(heap):
        lastelt = heap.pop()
        if heap:
            returnitem = heap[0]
            heap[0] = lastelt
            _siftup(heap, 0)
            return returnitem
        return lastelt
    return hq_heappop_impl