File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -937,6 +937,10 @@ print(Box.model_json_schema(mode='serialization'))
937
937
"""
938
938
```
939
939
940
+ 1 . If not specified, [ ` computed_field ` ] [ pydantic.fields.computed_field ] will implicitly convert the method
941
+ to a [ ` property ` ] [ ] . However, it is preferable to explicitly use the [ ` @property ` ] [ property ] decorator
942
+ for type checking purposes.
943
+
940
944
Here's an example using the ` model_dump ` method with a computed field:
941
945
942
946
``` python
@@ -949,7 +953,7 @@ class Box(BaseModel):
949
953
depth: float
950
954
951
955
@computed_field
952
- @ property # (1)!
956
+ @ property
953
957
def volume (self ) -> float :
954
958
return self .width * self .height * self .depth
955
959
@@ -959,10 +963,6 @@ print(b.model_dump())
959
963
# > {'width': 1.0, 'height': 2.0, 'depth': 3.0, 'volume': 6.0}
960
964
```
961
965
962
- 1 . If not specified, [ ` computed_field ` ] [ pydantic.fields.computed_field ] will implicitly convert the method
963
- to a [ ` property ` ] [ ] . However, it is preferable to explicitly use the [ ` @property ` ] [ property ] decorator
964
- for type checking purposes.
965
-
966
966
As with regular fields, computed fields can be marked as being deprecated:
967
967
968
968
``` python
You can’t perform that action at this time.
0 commit comments