"""Sample Python file for testing code structure analysis."""
from typing import List, Dict, Optional
def calculate_sum(numbers: List[int]) -> int:
"""Calculate the sum of a list of numbers.
Args:
numbers: List of integers to sum.
Returns:
The sum of all numbers.
"""
total = 0
for num in numbers:
total += num
return total
class DataProcessor:
"""A class for processing data."""
def __init__(self, config: Optional[Dict] = None):
"""Initialize the data processor.
Args:
config: Optional configuration dictionary.
"""
self.config = config or {}
def process_item(self, item: Dict) -> Dict:
"""Process a single data item.
Args:
item: The data item to process.
Returns:
The processed item.
"""
result = item.copy()
result["processed"] = True
return result
def process_batch(self, items: List[Dict]) -> List[Dict]:
"""Process a batch of data items.
Args:
items: List of data items to process.
Returns:
List of processed items.
"""
results = []
for item in items:
processed = self.process_item(item)
results.append(processed)
return results
class AdvancedProcessor(DataProcessor):
"""An advanced data processor with additional features."""
def __init__(self, config: Optional[Dict] = None):
"""Initialize the advanced processor."""
super().__init__(config)
self.stats = {"processed": 0, "errors": 0}
def process_with_stats(self, items: List[Dict]) -> List[Dict]:
"""Process items while tracking statistics.
Args:
items: List of data items to process.
Returns:
List of processed items.
"""
def update_stats(success: bool) -> None:
"""Update processing statistics."""
if success:
self.stats["processed"] += 1
else:
self.stats["errors"] += 1
results = []
for item in items:
try:
processed = self.process_item(item)
update_stats(True)
results.append(processed)
except Exception:
update_stats(False)
return results
def get_stats(self) -> Dict[str, int]:
"""Get processing statistics.
Returns:
Dictionary with processing statistics.
"""
return self.stats.copy()