{"record":{"id":"b563abed9ea60353","repo":"krahets/hello-algo","slug":"error-b563ab","errorCode":null,"errorMessage":"стек пуст","messagePattern":"стек пуст","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/python/chapter_stack_and_queue/array_stack.py","lineNumber":30,"sourceCode":"        \"\"\"Конструктор\"\"\"\n        self._stack: list[int] = []\n\n    def size(self) -> int:\n        \"\"\"Получение длины стека\"\"\"\n        return len(self._stack)\n\n    def is_empty(self) -> bool:\n        \"\"\"Проверка, пуст ли стек\"\"\"\n        return self.size() == 0\n\n    def push(self, item: int):\n        \"\"\"Поместить в стек\"\"\"\n        self._stack.append(item)\n\n    def pop(self) -> int:\n        \"\"\"Извлечь из стека\"\"\"\n        if self.is_empty():\n            raise IndexError(\"стек пуст\")\n        return self._stack.pop()\n\n    def peek(self) -> int:\n        \"\"\"Доступ к верхнему элементу стека\"\"\"\n        if self.is_empty():\n            raise IndexError(\"стек пуст\")\n        return self._stack[-1]\n\n    def to_list(self) -> list[int]:\n        \"\"\"Вернуть список для вывода\"\"\"\n        return self._stack\n\n\n\"\"\"Driver Code\"\"\"\nif __name__ == \"__main__\":\n    # Инициализация стека\n    stack = ArrayStack()\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/python/chapter_stack_and_queue/array_stack.py#L12-L48","documentation":"Raised by ArrayStack.pop() in chapter_stack_and_queue/array_stack.py:30 — IndexError(\"стек пуст\" = \"stack is empty\"). ArrayStack wraps a Python list; pop() delegates to list.pop after an explicit is_empty() check, giving a localized Russian message instead of Python's generic \"pop from empty list\".","triggerScenarios":"Calling pop() on a fresh or fully drained stack. More pops than pushes. Recursive/unwinding code that pops per frame without an empty guard.","commonSituations":"Mismatched push/pop in parsing or backtracking. Reusing a stack object across operations without clearing checks. Edge case where input triggers zero pushes.","solutions":["Guard: if not stk.is_empty(): stk.pop().","Use is_empty() as the loop/termination condition.","Wrap pop in try/except IndexError for optional unwinding.","Ensure every code path that pops has a matching push on the same logical scope."],"exampleFix":"// before\nx = stk.pop()\n// after\nx = stk.pop() if not stk.is_empty() else None","handlingStrategy":"validation","validationCode":"def safe_pop(stk):\n    return stk.pop() if not stk.is_empty() else None","typeGuard":"def stack_non_empty(stk) -> bool:\n    return not stk.is_empty()","tryCatchPattern":"try:\n    x = stk.pop()\nexcept IndexError:\n    x = None","preventionTips":["Match every pop with a push on the same logical scope","Use is_empty() as unwind-loop condition","In backtracking, pop only inside the branch that pushed"],"tags":["indexerror","stack","precondition","empty-state","python"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}