Skip to content

Commit 5e3bbb5

Browse files
authored
Better document SerializationInfo (#1747)
1 parent d9dacb0 commit 5e3bbb5

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

python/pydantic_core/core_schema.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,57 @@ class CoreConfig(TypedDict, total=False):
122122

123123

124124
class SerializationInfo(Protocol[ContextT]):
125+
"""Extra data used during serialization."""
126+
125127
@property
126-
def include(self) -> IncExCall: ...
128+
def include(self) -> IncExCall:
129+
"""The `include` argument set during serialization."""
130+
...
127131

128132
@property
129-
def exclude(self) -> IncExCall: ...
133+
def exclude(self) -> IncExCall:
134+
"""The `exclude` argument set during serialization."""
135+
...
130136

131137
@property
132138
def context(self) -> ContextT:
133-
"""Current serialization context."""
139+
"""The current serialization context."""
134140
...
135141

136142
@property
137-
def mode(self) -> str: ...
143+
def mode(self) -> Literal['python', 'json']:
144+
"""The serialization mode set during serialization."""
145+
...
138146

139147
@property
140-
def by_alias(self) -> bool: ...
148+
def by_alias(self) -> bool:
149+
"""The `by_alias` argument set during serialization."""
150+
...
141151

142152
@property
143-
def exclude_unset(self) -> bool: ...
153+
def exclude_unset(self) -> bool:
154+
"""The `exclude_unset` argument set during serialization."""
155+
...
144156

145157
@property
146-
def exclude_defaults(self) -> bool: ...
158+
def exclude_defaults(self) -> bool:
159+
"""The `exclude_defaults` argument set during serialization."""
160+
...
147161

148162
@property
149-
def exclude_none(self) -> bool: ...
163+
def exclude_none(self) -> bool:
164+
"""The `exclude_none` argument set during serialization."""
165+
...
150166

151167
@property
152-
def serialize_as_any(self) -> bool: ...
168+
def serialize_as_any(self) -> bool:
169+
"""The `serialize_as_any` argument set during serialization."""
170+
...
153171

154172
@property
155-
def round_trip(self) -> bool: ...
173+
def round_trip(self) -> bool:
174+
"""The `round_trip` argument set during serialization."""
175+
...
156176

157177
def mode_is_json(self) -> bool: ...
158178

@@ -162,18 +182,20 @@ def __repr__(self) -> str: ...
162182

163183

164184
class FieldSerializationInfo(SerializationInfo[ContextT], Protocol):
185+
"""Extra data used during field serialization."""
186+
165187
@property
166-
def field_name(self) -> str: ...
188+
def field_name(self) -> str:
189+
"""The name of the current field being serialized."""
190+
...
167191

168192

169193
class ValidationInfo(Protocol[ContextT]):
170-
"""
171-
Argument passed to validation functions.
172-
"""
194+
"""Extra data used during validation."""
173195

174196
@property
175197
def context(self) -> ContextT:
176-
"""Current validation context."""
198+
"""The current validation context."""
177199
...
178200

179201
@property

0 commit comments

Comments
 (0)