Skip to content

Commit 38bd6de

Browse files
dmontagunecaris
authored andcommitted
Handle list[str] as a field, etc.
1 parent ef4dd47 commit 38bd6de

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

graphene_pydantic/converters.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import typing as T
99
import uuid
10+
from types import GenericAlias
1011
from typing import Type, get_origin
1112

1213
import graphene
@@ -238,7 +239,11 @@ def find_graphene_type(
238239
return registry.get_type_for_model(type_)
239240
elif registry and (
240241
isinstance(type_, BaseModel)
241-
or (inspect.isclass(type_) and issubclass(type_, BaseModel))
242+
or (
243+
inspect.isclass(type_)
244+
and not isinstance(type_, GenericAlias)
245+
and issubclass(type_, BaseModel)
246+
)
242247
):
243248
# If it's a Pydantic model that hasn't yet been wrapped with a ObjectType,
244249
# we can put a placeholder in and request that `resolve_placeholders()`

tests/test_converters.py

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def test_iterables():
154154
field = _convert_field_from_spec("attr", (T.List[int], [1, 2]))
155155
assert isinstance(field.type.of_type, graphene.types.List)
156156

157+
if sys.version_info >= (3, 9):
158+
field = _convert_field_from_spec("attr", (list[int], [1, 2]))
159+
assert isinstance(field.type.of_type, graphene.types.List)
160+
157161
field = _convert_field_from_spec("attr", (list, [1, 2]))
158162
assert field.type.of_type == graphene.types.List
159163

0 commit comments

Comments
 (0)