{"record":{"id":"b062e3baa2895dca","repo":"krahets/hello-algo","slug":"error-b062e3","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/python/chapter_stack_and_queue/array_queue.py","lineNumber":51,"sourceCode":"        # Вычислить указатель хвоста, указывающий на индекс хвоста + 1\n        # С помощью операции взятия по модулю вернуть rear к началу после выхода за конец массива\n        rear: int = (self._front + self._size) % self.capacity()\n        # Добавить num в хвост очереди\n        self._nums[rear] = num\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"Извлечь из очереди\"\"\"\n        num: int = self.peek()\n        # Указатель head сдвигается на одну позицию назад; если он выходит за конец, то возвращается в начало массива\n        self._front = (self._front + 1) % self.capacity()\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"Доступ к элементу в начале очереди\"\"\"\n        if self.is_empty():\n            raise IndexError(\"очередь пуста\")\n        return self._nums[self._front]\n\n    def to_list(self) -> list[int]:\n        \"\"\"Вернуть список для вывода\"\"\"\n        res = [0] * self.size()\n        j: int = self._front\n        for i in range(self.size()):\n            res[i] = self._nums[(j % self.capacity())]\n            j += 1\n        return res\n\n\n\"\"\"Driver Code\"\"\"\nif __name__ == \"__main__\":\n    # Инициализация очереди\n    queue = ArrayQueue(10)\n\n    # Добавление элемента в очередь","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/python/chapter_stack_and_queue/array_queue.py#L33-L69","documentation":"Raised by ArrayQueue.peek() in chapter_stack_and_queue/array_queue.py:51 — IndexError(\"очередь пуста\" = \"queue is empty\"). peek returns self._nums[self._front]; on an empty queue _front is stale, so the guard is mandatory. pop() calls peek() first, so an empty pop surfaces as THIS error message, not a dedicated pop error.","triggerScenarios":"Calling peek() or pop() on an empty queue. Consuming more items than were pushed. Reading the head before the first push.","commonSituations":"Consumer started before producer. Unbalanced push/pop. Draining loop without is_empty() guard.","solutions":["Guard: if not q.is_empty(): q.peek().","Make is_empty() the loop condition for consumption.","Wrap pop in try/except IndexError since pop delegates to peek.","Seed the queue before starting consumers."],"exampleFix":"// before\nx = q.pop()\n// after\nx = q.pop() if not q.is_empty() else None","handlingStrategy":"validation","validationCode":"def safe_peek(q):\n    return q.peek() if not q.is_empty() else None","typeGuard":"def queue_non_empty(q) -> bool:\n    return not q.is_empty()","tryCatchPattern":"try:\n    x = q.pop()  # pop delegates to peek\nexcept IndexError:\n    x = None","preventionTips":["pop() raises the peek() message — guard once at the call site","Seed the queue before starting consumers","Use is_empty() as the consume-loop condition"],"tags":["indexerror","queue","ring-buffer","precondition","empty-state","python"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}