Skip to content

Commit a162db6

Browse files
author
Rami Chowdhury
committed
Handle native origins as well as typing origins
1 parent 9d2013f commit a162db6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

graphene_pydantic/converters.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections import OrderedDict
2+
from collections.abc import Mapping, Sequence
13
import typing as T
24
import uuid
35
import datetime
@@ -149,9 +151,13 @@ def convert_generic_type(type_, field, registry=None):
149151
# Python functions like `isinstance()` don't work
150152
if origin == T.Union:
151153
return convert_union_type(type_, field, registry)
152-
elif origin in (T.Dict, T.OrderedDict, T.Mapping):
154+
elif origin in (T.Dict, T.OrderedDict, T.Mapping, dict, OrderedDict) or issubclass(
155+
origin, Mapping
156+
):
153157
raise ConversionError("Don't know how to handle mappings in Graphene")
154-
elif origin in (T.List, T.Set, T.Collection, T.Iterable):
158+
elif origin in (T.List, T.Set, T.Collection, T.Iterable, list, set) or issubclass(
159+
origin, Sequence
160+
):
155161
return List(to_graphene_type(type_, field, registry))
156162
else:
157163
raise ConversionError(f"Don't know how to handle {type_} (generic: {origin})")

0 commit comments

Comments
 (0)