MCPcopy
hub / github.com/pydantic/pydantic / Model

Class Model

tests/test_computed_fields.py:179–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177
178def test_cached_property():
179 class Model(BaseModel):
180 minimum: int = Field(alias='min')
181 maximum: int = Field(alias='max')
182
183 @computed_field(alias='the magic number')
184 @cached_property
185 def random_number(self) -> int:
186 """An awesome area"""
187 return random.randint(self.minimum, self.maximum)
188
189 @cached_property
190 def cached_property_2(self) -> int:
191 return 42
192
193 @cached_property
194 def _cached_property_3(self) -> int:
195 return 43
196
197 rect = Model(min=10, max=10_000)
198 assert rect.__private_attributes__ == {}

Calls 2

FieldFunction · 0.90
PrivateAttrFunction · 0.90