Skip to content

Commit e07ed73

Browse files
authored
Merge pull request #9 from joshorr/josho/adjust-docs
docs: clarified a point in readme/docs.
2 parents 4f53bf1 + 6b9fbd0 commit e07ed73

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ from pydantic_partials import PartialModel, Missing, Partial
3232

3333
class MyModel(PartialModel):
3434
some_attr: str
35-
35+
another_field: str
3636

3737
# By default, Partial fields without any value will get set to a special `Missing` type.
3838
# Any field that is set to Missing is excluded from the model_dump/model_dump_json
@@ -53,6 +53,12 @@ assert obj.model_dump() == {}
5353

5454
# The json dump is also affected in the same way.
5555
assert obj.model_dump_json() == '{}'
56+
57+
# Any non-missing fields will be included when dumping/serializing model.
58+
obj.another_field = 'assigned-value'
59+
60+
# And now it's removed from the model-dump.
61+
assert obj.model_dump() == {'another_field': 'assigned-value'}
5662
```
5763

5864

docs/index.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from pydantic_partials import PartialModel, Missing, Partial
2424

2525
class MyModel(PartialModel):
2626
some_attr: str
27-
27+
another_field: str
2828

2929
# By default, Partial fields without any value will get set to a special `Missing` type.
3030
# Any field that is set to Missing is excluded from the model_dump/model_dump_json
@@ -45,6 +45,13 @@ assert obj.model_dump() == {}
4545

4646
# The json dump is also affected in the same way.
4747
assert obj.model_dump_json() == '{}'
48+
49+
# Any non-missing fields will be included when dumping/serializing model.
50+
obj.another_field = 'assigned-value'
51+
52+
# And now it's removed from the model-dump.
53+
assert obj.model_dump() == {'another_field': 'assigned-value'}
54+
4855
```
4956

5057

tests/test_doc_examples.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def test_doc_example__index__1():
55

66
class MyModel(PartialModel):
77
some_attr: str
8+
another_field: str
89

910
# By default, Partial fields without any value will get set to a special `Missing` type.
1011
# Any field that is set to Missing is excluded from the model_dump/model_dump_json
@@ -26,6 +27,12 @@ class MyModel(PartialModel):
2627
# The json dump is also affected in the same way.
2728
assert obj.model_dump_json() == '{}'
2829

30+
# Any non-missing fields will be included when dumping/serializing model.
31+
obj.another_field = 'assigned-value'
32+
33+
# And now it's removed from the model-dump.
34+
assert obj.model_dump() == {'another_field': 'assigned-value'}
35+
2936

3037
def test_doc_example__index__2():
3138
from pydantic_partials import PartialModel, Missing, MissingType, Partial, PartialConfigDict

0 commit comments

Comments
 (0)