{"record":{"id":"16710d19a0c2dca1","repo":"krahets/hello-algo","slug":"error-16710d","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/python/chapter_stack_and_queue/linkedlist_queue.py","lineNumber":56,"sourceCode":"            self._rear = node\n        # Если очередь не пуста, добавить этот узел после хвостового узла\n        else:\n            self._rear.next = node\n            self._rear = node\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"Извлечь из очереди\"\"\"\n        num = self.peek()\n        # Удалить головной узел\n        self._front = self._front.next\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._front.val\n\n    def to_list(self) -> list[int]:\n        \"\"\"Преобразовать в список для вывода\"\"\"\n        queue = []\n        temp = self._front\n        while temp:\n            queue.append(temp.val)\n            temp = temp.next\n        return queue\n\n\n\"\"\"Driver Code\"\"\"\nif __name__ == \"__main__\":\n    # Инициализация очереди\n    queue = LinkedListQueue()\n\n    # Добавление элемента в очередь","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/python/chapter_stack_and_queue/linkedlist_queue.py#L38-L74","documentation":"Raised by LinkedListQueue.peek() in chapter_stack_and_queue/linkedlist_queue.py:56 — IndexError(\"очередь пуста\" = \"queue is empty\"). peek returns self._front.val; on an empty queue self._front is None, so the guard prevents an AttributeError. pop() calls peek() first, so an empty pop surfaces as THIS message rather than a dedicated pop error.","triggerScenarios":"Calling peek() or pop() on an empty queue. Consuming more items than pushed. Reading the front before the first enqueue.","commonSituations":"Consumer started before producer. Draining loop without is_empty() guard. Reusing the queue across batches without resetting checks.","solutions":["Guard: if not q.is_empty(): q.peek().","Use is_empty() as 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 peek()'s message — guard once at the call site","Seed the queue before consumers start","Use is_empty() as the consume-loop condition"],"tags":["indexerror","queue","linked-list","precondition","empty-state","python"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}