Skip to content

Commit eb1eb7c

Browse files
committed
docs: added/changed doc-comments.
1 parent 0186934 commit eb1eb7c

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Custom Ones
22

33
/scripts
4-
4+
/api
55

66
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
77
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

pydantic_partials/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PartialConfigDict(ConfigDict):
99
"""
1010
Defaults to `True`.
1111
12-
If `True` (default): When class is created, all required attributes will be made `Partial`,
12+
- If `True` (default): When class is created, all required attributes will be made `Partial`,
1313
and their default set to `Missing`. This means that all attributes that don't have any
1414
default or default_factory defined will automatically have `MissingType`/`LazyType` added
1515
to their annotation and field default set to `Missing`/`Lazy`.
@@ -19,7 +19,7 @@ class PartialConfigDict(ConfigDict):
1919
This allows Pydantic to create an instance of the model without a value defined
2020
for partial fields.
2121
22-
If `False`: Class won't automatically add `Partial` fields.
22+
- If `False`: Class won't automatically add `Partial` fields.
2323
Instead adding them to individual fields will be up to the user.
2424
2525
The default value of any fields set by user to be `Partial` will still be adjusted

pydantic_partials/meta.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616

1717
# metaclass to make all fields in a model optional, useful for PATCH requests
18-
class _PartialMeta(ModelMetaclass):
18+
class PartialMeta(ModelMetaclass):
19+
""" Metaclass of `pydantic_partials.partial.PartialModel`, used to support partial fields,
20+
including the ability ot automatically apply `pydantic_partials.partial.Partial`[...] to fields
21+
via `pydantic_partials.config.PartialConfigDict.auto_partials` configuration option.
22+
"""
1923
model_partial_fields: typing.ClassVar[set[str]]
2024
""" Set of strings representing field names that can be missing from validation/serialization.
2125
If they are missing, they will return the `Missing` sentinel value and the field will be entirely
@@ -53,7 +57,7 @@ def __new__(
5357
"""
5458
5559
Args:
56-
auto_partials: For more details see `pydantic_partials.config.PartialConfigDict.auto_partial`.
60+
auto_partials: For more details see `pydantic_partials.config.PartialConfigDict.auto_partials`.
5761
If `Default`: Inherit behavior from parent/model_config; otherwise defaults to `True`.
5862
If `True` (default): Will automatically make all fields on the model `Partial`.
5963
If `False`: User needs to mark individual fields as `Partial` where they want.

pydantic_partials/partial.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pydantic import BaseModel, model_serializer, JsonValue
55

6-
from .meta import _PartialMeta
6+
from .meta import PartialMeta
77
from .sentinels import Missing, MissingType
88

99
from logging import getLogger
@@ -23,18 +23,25 @@ class PartialModel(
2323

2424
# Need metaclass to examine fields for missing type
2525
# and also to auto-add missing type if desired.
26-
metaclass=_PartialMeta,
26+
metaclass=PartialMeta,
2727

2828
# Needed so `Missing` default values will be validated and therefore the `PydanticOmit` will be
2929
# raised and inform Pydantic to ignore/omit the field value.
3030
validate_default=True
3131
):
32-
""" Class Args:
33-
auto_partial: For more details see `pydantic_partials.config.PartialConfigDict.auto_partial`.
34-
If `Default`: Inherit behavior from parent/model_config; otherwise defaults to `True`.
35-
If `True` (default): Will automatically make all fields on the model `Partial`.
36-
If `False`: User needs to mark individual fields as `Partial` where they want.
3732
"""
33+
Class Args:
34+
35+
- auto_partial: For more details see `pydantic_partials.config.PartialConfigDict.auto_partials`.
36+
- If `Default`: Inherit behavior from parent/model_config; otherwise defaults to `True`.
37+
- If `True` (default): Will automatically make all fields on the model `Partial`.
38+
- If `False`: User needs to mark individual fields as `Partial` where they want.
39+
"""
40+
41+
def __init__(self, *args, **kwargs):
42+
""" Pydantic partial model class, with ability to easily dynamically omit fields when serializing a model.
43+
"""
44+
super().__init__(*args, **kwargs)
3845

3946
if not typing.TYPE_CHECKING:
4047

pydantic_partials/sentinels.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77

88
class MissingType(Sentinel):
9-
# See (https://docs.pydantic.dev/latest/concepts/json_schema/#modifying-the-schema).
9+
""" Class/Type of `Missing`, a sentinel that is used to indicate if a field is missing its value
10+
in a `pydantic_partials.partial.PartialModel` subclass.
11+
"""
12+
# Notes/See (https://docs.pydantic.dev/latest/concepts/json_schema/#modifying-the-schema).
1013

1114
@classmethod
1215
def __get_pydantic_core_schema__(
@@ -41,6 +44,8 @@ def _serialize(value: Any) -> 'MissingType':
4144

4245

4346
Missing = MissingType()
47+
""" Returned as attribute value when attribute value is missing. Can also be set on attribute to indicate it's missing.
48+
"""
4449

4550
T = TypeVar('T')
4651

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "pydantic-partials"
33
version = "1.0.0"
4-
description = "Pydantic partial model class, with ability to easily dynamically omit fields when seralizing a model."
4+
description = "Pydantic partial model class, with ability to easily dynamically omit fields when serializing a model."
55

66
authors = ["Josh Orr <[email protected]>"]
77
packages = [{include = "pydantic_partials"}]

0 commit comments

Comments
 (0)