@@ -63,13 +63,14 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaH
6363 The Pydantic core schema.
6464 """
6565 schema = handler (source_type )
66- globalns , localns = handler ._get_types_namespace ()
6766 try :
67+ # Do not pass in globals as the function could be defined in a different module.
68+ # Instead, let `get_function_return_type` infer the globals to use, but still pass
69+ # in locals that may contain a parent/rebuild namespace:
6870 return_type = _decorators .get_function_return_type (
6971 self .func ,
7072 self .return_type ,
71- globalns = globalns ,
72- localns = localns ,
73+ localns = handler ._get_types_namespace ().locals ,
7374 )
7475 except NameError as e :
7576 raise PydanticUndefinedAnnotation .from_name_error (e ) from e
@@ -166,11 +167,13 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaH
166167 schema = handler (source_type )
167168 globalns , localns = handler ._get_types_namespace ()
168169 try :
170+ # Do not pass in globals as the function could be defined in a different module.
171+ # Instead, let `get_function_return_type` infer the globals to use, but still pass
172+ # in locals that may contain a parent/rebuild namespace:
169173 return_type = _decorators .get_function_return_type (
170174 self .func ,
171175 self .return_type ,
172- globalns = globalns ,
173- localns = localns ,
176+ localns = handler ._get_types_namespace ().locals ,
174177 )
175178 except NameError as e :
176179 raise PydanticUndefinedAnnotation .from_name_error (e ) from e
0 commit comments