From 801333eae7a50f96b6d3220ac818b3040f7faf50 Mon Sep 17 00:00:00 2001 From: "Tjeerd.Verschragen" Date: Mon, 3 Jul 2023 13:06:13 +0200 Subject: [PATCH] Add pydantic conversion compatibility with specialized list class - Modified `StrawberryAnnotation._is_list` to check if the `annotation` extends from the `list` type, enabling it to be considered a list. - in `StrawberryAnnotation` Moved the `_is_list` check before the `_is_generic` check in `resolve` to avoid `unsupported` error in `_is_generic` before it checked `_is_list`. --- strawberry/annotation.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/strawberry/annotation.py b/strawberry/annotation.py index 8cac2baf96..440f0a5bd9 100644 --- a/strawberry/annotation.py +++ b/strawberry/annotation.py @@ -129,6 +129,8 @@ def resolve(self) -> Union[StrawberryType, type]: evaled_type = self._strip_async_type(evaled_type) if self._is_lazy_type(evaled_type): return evaled_type + if self._is_list(evaled_type): + return self.create_list(evaled_type) if self._is_generic(evaled_type): if any(is_type_var(type_) for type_ in get_args(evaled_type)): @@ -139,8 +141,6 @@ def resolve(self) -> Union[StrawberryType, type]: # a StrawberryType if self._is_enum(evaled_type): return self.create_enum(evaled_type) - if self._is_list(evaled_type): - return self.create_list(evaled_type) elif self._is_optional(evaled_type, args): return self.create_optional(evaled_type) elif self._is_union(evaled_type, args): @@ -286,8 +286,14 @@ def _is_list(cls, annotation: Any) -> bool: """Returns True if annotation is a List""" annotation_origin = get_origin(annotation) + annotation_mro = getattr(annotation, "__mro__", []) + is_list = any(x is list for x in annotation_mro) - return (annotation_origin in (list, tuple)) or annotation_origin is abc.Sequence + return ( + (annotation_origin in (list, tuple)) + or annotation_origin is abc.Sequence + or is_list + ) @classmethod def _is_strawberry_type(cls, evaled_type: Any) -> bool: