| 26 | |
| 27 | def test_computed_fields_get(): |
| 28 | class Rectangle(BaseModel): |
| 29 | width: int |
| 30 | length: int |
| 31 | |
| 32 | @computed_field |
| 33 | def area(self) -> int: |
| 34 | """An awesome area""" |
| 35 | return self.width * self.length |
| 36 | |
| 37 | @computed_field(title='Pikarea', description='Another area') |
| 38 | @property |
| 39 | def area2(self) -> int: |
| 40 | return self.width * self.length |
| 41 | |
| 42 | @property |
| 43 | def double_width(self) -> int: |
| 44 | return self.width * 2 |
| 45 | |
| 46 | rect = Rectangle(width=10, length=5) |
| 47 | assert set(Rectangle.model_fields) == {'width', 'length'} |
no outgoing calls