Skip to content

Commit 10ee0df

Browse files
committed
docs: Fix flake8 violations in experimental/marshmallow.py
- Wrap overlong lines (E501) in class summary, _serialize and _deserialize summaries, and QUANTITY_FIELD_CLASSES docstring - _serialize: add missing Raises section for TypeError (DOC501/DOC503) - _deserialize: document both TypeError and ValidationError in Raises; use bare exception name 'ValidationError' for pydoclint compatibility (DOC503 cannot match cross-reference markup in exception names), with a link to marshmallow.ValidationError in the description - QuantitySchema: remove blank line between Example: header and code fence (D412) - _deserialize summary: rewrite as single line ending with period to fix D205 and D400 Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent b62e2ee commit 10ee0df

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

‎src/frequenz/quantities/experimental/marshmallow.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343

4444

4545
class _QuantityField(Field[Quantity]):
46-
"""A custom field for [`Quantity`][frequenz.quantities.Quantity] objects supporting per-field serialization.
46+
"""A custom field for [`Quantity`][frequenz.quantities.Quantity] objects.
47+
48+
Supports per-field serialization configuration.
4749
4850
This class handles serialization and deserialization of ALL
4951
[`Quantity`][frequenz.quantities.Quantity] subclasses.
@@ -82,7 +84,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
8284
def _serialize(
8385
self, value: Quantity | None, attr: str | None, obj: Any, **kwargs: Any
8486
) -> Any:
85-
"""Serialize a [`Quantity`][frequenz.quantities.Quantity] value based on per-field configuration.
87+
"""Serialize a [`Quantity`][frequenz.quantities.Quantity] based on per-field configuration.
8688
8789
Args:
8890
value: The quantity to serialize, or `None`.
@@ -93,6 +95,12 @@ def _serialize(
9395
Returns:
9496
The string representation with unit if serializing as string, or
9597
the raw base float value otherwise. `None` if `value` is `None`.
98+
99+
Raises:
100+
TypeError: If [`.field_type`][.field_type] is not set to a
101+
[`Quantity`][frequenz.quantities.Quantity] subclass, or if
102+
`value` is not a [`Quantity`][frequenz.quantities.Quantity]
103+
instance.
96104
"""
97105
if self.field_type is None or not issubclass(self.field_type, Quantity):
98106
raise TypeError(
@@ -124,7 +132,7 @@ def _serialize(
124132
def _deserialize(
125133
self, value: Any, attr: str | None, data: Any, **kwargs: Any
126134
) -> Quantity:
127-
"""Deserialize a float, int, or string into a [`Quantity`][frequenz.quantities.Quantity] instance.
135+
"""Deserialize a [`Quantity`][frequenz.quantities.Quantity] from a float, int, or string.
128136
129137
Args:
130138
value: The raw value to deserialize (float, int, or string).
@@ -136,8 +144,10 @@ def _deserialize(
136144
The deserialized quantity instance.
137145
138146
Raises:
139-
[`ValidationError`][marshmallow.ValidationError]: If the input type is
140-
invalid or parsing fails.
147+
TypeError: If [`.field_type`][.field_type] is not set to a
148+
[`Quantity`][frequenz.quantities.Quantity] subclass.
149+
ValidationError: If the input type is invalid or parsing fails
150+
(see [`marshmallow.ValidationError`][marshmallow.ValidationError]).
141151
"""
142152
if self.field_type is None or not issubclass(self.field_type, Quantity):
143153
raise TypeError(
@@ -240,18 +250,19 @@ class VoltageField(_QuantityField):
240250
Temperature: TemperatureField,
241251
Voltage: VoltageField,
242252
}
243-
"""The mapping from [`Quantity`][frequenz.quantities.Quantity] subclasses to their corresponding field subclasses.
253+
"""The mapping from [`Quantity`][frequenz.quantities.Quantity] subclasses to
254+
their corresponding field subclasses.
244255
245256
This mapping is used in [`QuantitySchema.TYPE_MAPPING`][..QuantitySchema.TYPE_MAPPING] to
246-
determine the correct field class for each [`Quantity`][frequenz.quantities.Quantity] subclass.
257+
determine the correct field class for each [`Quantity`][frequenz.quantities.Quantity]
258+
subclass.
247259
"""
248260

249261

250262
class QuantitySchema(Schema):
251263
"""A schema for quantities.
252264
253265
Example:
254-
255266
```python
256267
from dataclasses import dataclass, field
257268
from marshmallow_dataclass import class_schema

0 commit comments

Comments
 (0)