88import typing as T
99import uuid
1010from types import UnionType
11- from typing import get_origin
11+ from typing import Type , get_origin
1212
1313import graphene
1414from graphene import (
2525 UUID ,
2626 Union ,
2727)
28- from graphene .types .base import BaseType
2928from graphene .types .datetime import Date , DateTime , Time
3029from pydantic import BaseModel
3130from pydantic .fields import FieldInfo
3231from pydantic_core import PydanticUndefined
3332
3433from .registry import Registry
35- from .util import construct_union_class_name
34+ from .util import construct_union_class_name , evaluate_forward_ref
3635
3736GRAPHENE2 = graphene .VERSION [0 ] < 3
3837
@@ -168,7 +167,7 @@ def convert_pydantic_type(
168167 registry : Registry ,
169168 parent_type : T .Type = None ,
170169 model : T .Type [BaseModel ] = None ,
171- ) -> BaseType : # noqa: C901
170+ ) -> Type : # noqa: C901
172171 """
173172 Convert a Pydantic type to a Graphene Field type, including not just the
174173 native Python type but any additional metadata (e.g. shape) that Pydantic
@@ -190,7 +189,7 @@ def find_graphene_type(
190189 registry : Registry ,
191190 parent_type : T .Type = None ,
192191 model : T .Type [BaseModel ] = None ,
193- ) -> BaseType : # noqa: C901
192+ ) -> Type : # noqa: C901
194193 """
195194 Map a native Python type to a Graphene-supported Field type, where possible,
196195 throwing an error if we don't know what to map it to.
@@ -254,8 +253,9 @@ def find_graphene_type(
254253 "the forward reference. Did you call `resolve_placeholders()`? "
255254 "See the README for more on forward references."
256255 )
256+
257257 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 )
259259 # TODO: make this behavior optional. maybe this is a place for the TypeOptions to play a role?
260260 if registry :
261261 registry .add_placeholder_for_model (resolved )
@@ -294,7 +294,7 @@ def convert_generic_python_type(
294294 registry : Registry ,
295295 parent_type : T .Type = None ,
296296 model : T .Type [BaseModel ] = None ,
297- ) -> BaseType : # noqa: C901
297+ ) -> Type : # noqa: C901
298298 """
299299 Convert annotated Python generic types into the most appropriate Graphene
300300 Field type -- e.g. turn `typing.Union` into a Graphene Union.
0 commit comments