8
8
import typing as T
9
9
import uuid
10
10
from types import UnionType
11
- from typing import get_origin
11
+ from typing import Type , get_origin
12
12
13
13
import graphene
14
14
from graphene import (
25
25
UUID ,
26
26
Union ,
27
27
)
28
- from graphene .types .base import BaseType
29
28
from graphene .types .datetime import Date , DateTime , Time
30
29
from pydantic import BaseModel
31
30
from pydantic .fields import FieldInfo
32
31
from pydantic_core import PydanticUndefined
33
32
34
33
from .registry import Registry
35
- from .util import construct_union_class_name
34
+ from .util import construct_union_class_name , evaluate_forward_ref
36
35
37
36
GRAPHENE2 = graphene .VERSION [0 ] < 3
38
37
@@ -168,7 +167,7 @@ def convert_pydantic_type(
168
167
registry : Registry ,
169
168
parent_type : T .Type = None ,
170
169
model : T .Type [BaseModel ] = None ,
171
- ) -> BaseType : # noqa: C901
170
+ ) -> Type : # noqa: C901
172
171
"""
173
172
Convert a Pydantic type to a Graphene Field type, including not just the
174
173
native Python type but any additional metadata (e.g. shape) that Pydantic
@@ -190,7 +189,7 @@ def find_graphene_type(
190
189
registry : Registry ,
191
190
parent_type : T .Type = None ,
192
191
model : T .Type [BaseModel ] = None ,
193
- ) -> BaseType : # noqa: C901
192
+ ) -> Type : # noqa: C901
194
193
"""
195
194
Map a native Python type to a Graphene-supported Field type, where possible,
196
195
throwing an error if we don't know what to map it to.
@@ -254,8 +253,9 @@ def find_graphene_type(
254
253
"the forward reference. Did you call `resolve_placeholders()`? "
255
254
"See the README for more on forward references."
256
255
)
256
+
257
257
module_ns = sys .modules [sibling .__module__ ].__dict__
258
- resolved = T . cast ( T . Any , type_ ). _evaluate (type_ , module_ns , None )
258
+ resolved = evaluate_forward_ref (type_ , module_ns , None )
259
259
# TODO: make this behavior optional. maybe this is a place for the TypeOptions to play a role?
260
260
if registry :
261
261
registry .add_placeholder_for_model (resolved )
@@ -294,7 +294,7 @@ def convert_generic_python_type(
294
294
registry : Registry ,
295
295
parent_type : T .Type = None ,
296
296
model : T .Type [BaseModel ] = None ,
297
- ) -> BaseType : # noqa: C901
297
+ ) -> Type : # noqa: C901
298
298
"""
299
299
Convert annotated Python generic types into the most appropriate Graphene
300
300
Field type -- e.g. turn `typing.Union` into a Graphene Union.
0 commit comments