Skip to content

Commit

Permalink
Fix _serialize type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed May 28, 2024
1 parent 7b0b051 commit ca16dd1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/marshmallow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ def _call_and_store(getter_func, data, *, field_name, error_store, index=None):
return error.valid_data or missing
return value

def _serialize(self, obj: dict | typing.Iterable[dict], *, many: bool = False):
def _serialize(
self, obj: typing.Any | typing.Iterable[dict], *, many: bool = False
):
"""Serialize ``obj``.
:param obj: The object(s) to serialize.
Expand All @@ -510,10 +512,7 @@ def _serialize(self, obj: dict | typing.Iterable[dict], *, many: bool = False):
Renamed from ``marshal``.
"""
if many and obj is not None:
return [
self._serialize(d, many=False)
for d in typing.cast(typing.Iterable[dict], obj)
]
return [self._serialize(d, many=False) for d in obj]
ret = self.dict_class()
for attr_name, field_obj in self.dump_fields.items():
value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
Expand Down

0 comments on commit ca16dd1

Please sign in to comment.