From ca16dd1d82fc95cbbdba679049f403806efc7fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Tue, 28 May 2024 20:29:01 +0200 Subject: [PATCH] Fix _serialize type hints --- src/marshmallow/schema.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/marshmallow/schema.py b/src/marshmallow/schema.py index 444ac698a..87e9d3bbd 100644 --- a/src/marshmallow/schema.py +++ b/src/marshmallow/schema.py @@ -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. @@ -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)