8000 Fix code annotation in `@computed_field` documentation (#11693) · pydantic/pydantic@4a8c929 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a8c929

Browse files
authored
Fix code annotation in @computed_field documentation (#11693)
1 parent a8b8b5f commit 4a8c929

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/concepts/fields.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,10 @@ print(Box.model_json_schema(mode='serialization'))
937937
"""
938938
```
939939

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+
940944
Here's an example using the `model_dump` method with a computed field:
941945

942946
```python
@@ -949,7 +953,7 @@ class Box(BaseModel):
949953
depth: float
950954

951955
@computed_field
952-
@property # (1)!
956+
@property
953957
def volume(self) -> float:
954958
return self.width * self.height * self.depth
955959

@@ -959,10 +963,6 @@ print(b.model_dump())
959963
#> {'width': 1.0, 'height': 2.0, 'depth': 3.0, 'volume': 6.0}
960964
```
961965

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-
966966
As with regular fields, computed fields can be marked as being deprecated:
967967

968968
```python

0 commit comments

Comments
 (0)
0