py-08-pydantic-orders
1.000
Proposed solution
```python
from pydantic import BaseModel, Field, computed_field
class Order(BaseModel):
id: int
customer: str = Field(min_length=1)
quantity: int = Field(gt=0)
unit_price: float = Field(ge=0)
@computed_field(return_type=float)
@property
def total(self) -> float:
return self.quantity * self.unit_price
def parse_orders(rows: list[dict]) -> list[Order]:
return [Order(**row) for row in rows]
```Test output (stdout)
......... [100%] 9 passed in 0.05s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.