UNPKG

codebridge-ai

Version:

Complete fullstack AI coding platform with AST-based code integration and local LLM support. Now with comprehensive web technology support (HTML/CSS/JS) plus JavaScript, Python, Rust, and C++.

21 lines 2.44 kB
{ "timestamp": "2025-08-02T14:34:13.873Z", "model": "deepseek-coder:6.7b", "language": "python", "scenario": "class-improvement", "task": "Add empty check, peek method, size property, and type hints", "originalCode": "class Stack:\n def __init__(self):\n self.items = []\n \n def push(self, item):\n self.items.append(item)\n \n def pop(self):\n return self.items.pop()", "rawResponse": "Here is your updated python class:\n\n```python\nfrom typing import Any\n\nclass Stack:\n def __init__(self):\n self.items : list = []\n \n def push(self, item: Any) -> None:\n self.items.append(item)\n \n def pop(self) -> Any:\n if not self.is_empty():\n return self.items.pop()\n else:\n raise IndexError('Pop from empty stack')\n \n def peek(self) -> Any:\n if not self.is_empty():\n return self.items[-1]\n else:\n raise IndexError('Peek from empty stack')\n \n @property\n def size(self) -> int:\n return len(self.items)\n \n def is_empty(self) -> bool:\n return not self.items\n```\nThis class now includes a peek method to view the top item without removing it, a size property that returns the current number of items in the stack, and type hints for all methods using Python's built-in typing module. The is_empty helper function has been added to check if the stack is empty before popping or peeking.\n", "improvedCode": "from typing import Any\n\nclass Stack:\n def __init__(self):\n self.items : list = []\n \n def push(self, item: Any) -> None:\n self.items.append(item)\n \n def pop(self) -> Any:\n if not self.is_empty():\n return self.items.pop()\n else:\n raise IndexError('Pop from empty stack')\n \n def peek(self) -> Any:\n if not self.is_empty():\n return self.items[-1]\n else:\n raise IndexError('Peek from empty stack')\n \n @property\n def size(self) -> int:\n return len(self.items)\n \n def is_empty(self) -> bool:\n return not self.items", "duration": 6381, "success": true, "qualityMetrics": { "hasCode": true, "hasTypeHints": true, "hasErrorHandling": true, "score": 0.6666666666666667, "rawScore": 0.8, "maxScore": 1.2 }, "error": null }