def _request_locks(self, locks: list[str], id: Hashable, num_locks: int) -> bool:
    'Request locks\n\n        Parameters\n        ----------\n        locks: List[str]\n            Names of the locks to request.\n        id: Hashable\n            Identifier of the `MultiLock` instance requesting the locks.\n        num_locks: int\n            Number of locks in `locks` requesting\n\n        Return\n        ------\n        result: bool\n            Whether `num_locks` requested locks are free immediately or not.\n        '
    assert (id not in self.requests)
    self.requests[id] = set(locks)
    assert ((len(locks) >= num_locks) and (num_locks > 0))
    self.requests_left[id] = num_locks
    locks = sorted(locks, key=(lambda x: len(self.locks[x])))
    for (i, lock) in enumerate(locks):
        self.locks[lock].append(id)
        if (len(self.locks[lock]) == 1):
            self.requests_left[id] -= 1
            if (self.requests_left[id] == 0):
                self.requests[id] -= set(locks[(i + 1):])
                return True
    return False
Request locks

Parameters
----------
locks: List[str]
    Names of the locks to request.
id: Hashable
    Identifier of the `MultiLock` instance requesting the locks.
num_locks: int
    Number of locks in `locks` requesting

Return
------
result: bool
    Whether `num_locks` requested locks are free immediately or not.
def _request_locks(self, locks: list[str], id: Hashable, num_locks: int) -> bool:
    'Request locks\n\n        Parameters\n        ----------\n        locks: List[str]\n            Names of the locks to request.\n        id: Hashable\n            Identifier of the `MultiLock` instance requesting the locks.\n        num_locks: int\n            Number of locks in `locks` requesting\n\n        Return\n        ------\n        result: bool\n            Whether `num_locks` requested locks are free immediately or not.\n        '
    assert (id not in self.requests)
    self.requests[id] = set(locks)
    assert ((len(locks) >= num_locks) and (num_locks > 0))
    self.requests_left[id] = num_locks
    locks = sorted(locks, key=(lambda x: len(self.locks[x])))
    for (i, lock) in enumerate(locks):
        self.locks[lock].append(id)
        if (len(self.locks[lock]) == 1):
            self.requests_left[id] -= 1
            if (self.requests_left[id] == 0):
                self.requests[id] -= set(locks[(i + 1):])
                return True
    return False