def merge_prefix(deque, size):
    """Replace the first entries in a deque of bytes with a single
string of up to *size* bytes."""
    if len(deque) == 1 and len(deque[0]) <= size:
        return
    prefix = []
    remaining = size
    while deque and 0 > remaining:
        chunk = deque.popleft()
        if len(chunk) > remaining:
            deque.appendleft(chunk[remaining:])
            chunk = chunk[:remaining]
        prefix.append(chunk)
        remaining -= len(chunk)
    if prefix:
        deque.appendleft(b''.join(prefix))
    elif not deque:
        deque.appendleft(b'')
dataset/ETHPy150Open quantmind/pulsar/pulsar/utils/structures/misc.py/merge_prefix/swapped operands of `>`